178 lines
3.4 KiB
Go
178 lines
3.4 KiB
Go
package compiler
|
|
|
|
import "testing"
|
|
import "runtime"
|
|
|
|
var nativeLineBreak = "\n"
|
|
func init () {
|
|
if runtime.GOOS == "windows" {
|
|
nativeLineBreak = "\r\n"
|
|
}
|
|
}
|
|
|
|
func TestHelloWorld (test *testing.T) {
|
|
testUnit (test,
|
|
"/test-data/data/hello", nil,
|
|
"", "Hello, world!" + nativeLineBreak,
|
|
0,
|
|
)}
|
|
|
|
func TestPuts (test *testing.T) {
|
|
testUnit (test,
|
|
"/test-data/data/puts", nil,
|
|
"", "hello" + nativeLineBreak,
|
|
0,
|
|
)}
|
|
|
|
func TestExitCode13 (test *testing.T) {
|
|
testUnit (test,
|
|
"/test-data/data/exit-code-13", nil,
|
|
"", "",
|
|
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,
|
|
)}
|
|
|
|
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",
|
|
// )}
|
|
|
|
func TestSimpleInterface (test *testing.T) {
|
|
testUnit (test,
|
|
"/test-data/data/simple-interface", nil,
|
|
"", "",
|
|
9,
|
|
)}
|
|
|
|
func TestWriterInterface (test *testing.T) {
|
|
dependencies := []string {
|
|
compileDependency(test, "io"),
|
|
}
|
|
testUnit (test,
|
|
"/test-data/data/writer", dependencies,
|
|
"", "well hello their" + nativeLineBreak,
|
|
0,
|
|
)}
|
|
|
|
func TestMatchExitCode (test *testing.T) {
|
|
testUnit (test,
|
|
"/test-data/data/match-exit-code", nil,
|
|
"", "",
|
|
7,
|
|
)}
|
|
|
|
func TestMatchPrint (test *testing.T) {
|
|
dependencies := []string {
|
|
compileDependency(test, "io"),
|
|
}
|
|
testUnit (test,
|
|
"/test-data/data/match-print", dependencies,
|
|
"", "F64" + nativeLineBreak,
|
|
0,
|
|
)}
|
|
|
|
func TestMatchDefaultPrint (test *testing.T) {
|
|
dependencies := []string {
|
|
compileDependency(test, "io"),
|
|
}
|
|
testUnit (test,
|
|
"/test-data/data/match-default-print", dependencies,
|
|
"", "something else" + nativeLineBreak,
|
|
0,
|
|
)}
|
|
|
|
func TestSwitchExitCode (test *testing.T) {
|
|
testUnit (test,
|
|
"/test-data/data/switch-exit-code", nil,
|
|
"", "",
|
|
4,
|
|
)}
|
|
|
|
func TestReturnAssign (test *testing.T) {
|
|
dependencies := []string {
|
|
compileDependency(test, "io"),
|
|
}
|
|
testUnit (test,
|
|
"/test-data/data/return-assign", dependencies,
|
|
"", "false" + nativeLineBreak,
|
|
0,
|
|
)}
|
|
|
|
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,
|
|
)}
|
|
|
|
func TestForSimple (test *testing.T) {
|
|
testUnit (test,
|
|
"/test-data/data/for-simple", nil,
|
|
"", "",
|
|
0,
|
|
)}
|
|
|
|
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,
|
|
0,
|
|
)}
|
|
|
|
func TestForStringArrayOnce (test *testing.T) {
|
|
dependencies := []string {
|
|
compileDependency(test, "io"),
|
|
}
|
|
testUnit (test,
|
|
"/test-data/data/for-string-array-once", dependencies,
|
|
"", "abc" + nativeLineBreak,
|
|
0,
|
|
)}
|
|
|
|
func TestForBreakBranch (test *testing.T) {
|
|
dependencies := []string {
|
|
compileDependency(test, "io"),
|
|
}
|
|
testUnit (test,
|
|
"/test-data/data/for-break-branch", dependencies,
|
|
"", "iter" + nativeLineBreak + "iter" + nativeLineBreak,
|
|
0,
|
|
)}
|