2024-02-26 18:46:30 +00:00
|
|
|
package compiler
|
|
|
|
|
|
|
|
import "testing"
|
2024-03-31 04:39:43 +00:00
|
|
|
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,
|
2024-03-31 04:39:43 +00:00
|
|
|
"", "Hello, world!" + nativeLineBreak,
|
2024-02-26 18:46:30 +00:00
|
|
|
0,
|
|
|
|
)}
|
2024-02-26 19:03:10 +00:00
|
|
|
|
2024-03-26 05:18:39 +00:00
|
|
|
func TestPuts (test *testing.T) {
|
|
|
|
testUnit (test,
|
|
|
|
"/test-data/data/puts", nil,
|
2024-03-31 04:39:43 +00:00
|
|
|
"", "hello" + nativeLineBreak,
|
2024-03-26 05:18:39 +00:00
|
|
|
0,
|
|
|
|
)}
|
|
|
|
|
2024-02-26 19:03:10 +00:00
|
|
|
func TestExitCode13 (test *testing.T) {
|
|
|
|
testUnit (test,
|
2024-03-25 00:09:10 +00:00
|
|
|
"/test-data/data/exit-code-13", nil,
|
2024-02-26 19:03:10 +00:00
|
|
|
"", "",
|
|
|
|
13,
|
|
|
|
)}
|
2024-02-26 19:33:31 +00:00
|
|
|
|
|
|
|
func TestSystemInclude (test *testing.T) {
|
|
|
|
testUnit (test,
|
2024-03-25 00:09:10 +00:00
|
|
|
"/test-data/data/system-include", nil,
|
2024-03-31 04:39:43 +00:00
|
|
|
"", "Hello, /usr/include!" + nativeLineBreak,
|
2024-02-27 04:48:38 +00:00
|
|
|
0,
|
|
|
|
)}
|
|
|
|
|
|
|
|
func TestSystemSrc (test *testing.T) {
|
|
|
|
dependencies := []string {
|
|
|
|
compileDependency(test, "io"),
|
|
|
|
}
|
|
|
|
testUnit (test,
|
2024-03-25 00:09:10 +00:00
|
|
|
"/test-data/data/system-src", dependencies,
|
2024-03-31 04:39:43 +00:00
|
|
|
"", "Hello, /usr/src!" + nativeLineBreak,
|
2024-02-26 19:33:31 +00:00
|
|
|
0,
|
|
|
|
)}
|
2024-02-27 05:08:36 +00:00
|
|
|
|
|
|
|
func TestArgC (test *testing.T) {
|
|
|
|
testUnit (test,
|
|
|
|
"/test-data/data/argc", nil,
|
|
|
|
"", "",
|
|
|
|
2, "arg1", "arg2",
|
|
|
|
)}
|
2024-02-27 05:22:02 +00:00
|
|
|
|
|
|
|
// 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,
|
2024-03-25 00:09:10 +00:00
|
|
|
"/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,
|
2024-03-31 04:39:43 +00:00
|
|
|
"", "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,
|
2024-03-25 00:09:10 +00:00
|
|
|
"/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,
|
2024-03-25 00:09:10 +00:00
|
|
|
"/test-data/data/match-print", dependencies,
|
2024-03-31 04:39:43 +00:00
|
|
|
"", "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,
|
2024-03-31 04:39:43 +00:00
|
|
|
"", "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,
|
2024-03-25 00:09:10 +00:00
|
|
|
"/test-data/data/return-assign", dependencies,
|
2024-03-31 04:39:43 +00:00
|
|
|
"", "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,
|
2024-03-31 04:39:43 +00:00
|
|
|
"", "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,
|
2024-03-31 04:39:43 +00:00
|
|
|
"", "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,
|
2024-03-31 04:39:43 +00:00
|
|
|
"", "iter" + nativeLineBreak + "iter" + nativeLineBreak,
|
2024-03-24 07:09:33 +00:00
|
|
|
0,
|
|
|
|
)}
|