-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoi_test.go
54 lines (50 loc) · 1.15 KB
/
toi_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"os"
"testing"
)
func TestToi(t *testing.T) {
cases := []struct {
Filename string
Stdin string
}{
{"arrays", ""},
{"assignment", ""},
{"binaryOperators", ""},
{"builtinFuncs", "10\n20"},
{"comment", ""},
{"conditionals", ""},
{"for", ""},
{"functions", ""},
{"if", ""},
{"inputLines", "asdf\nkek"},
{"logicalOperators", ""},
{"loops", ""},
{"maps", ""},
{"math", ""},
{"printNumbers", ""},
{"strings", ""},
{"types", ""},
{"while", ""},
}
for _, testCase := range cases {
t.Run(testCase.Filename, func(t *testing.T) {
baseFilename := "toi/" + testCase.Filename
expectedBytes, err := os.ReadFile(baseFilename + ".out")
if err != nil {
t.Errorf("error readint out file for '%s': %v", testCase.Filename, err)
t.FailNow()
return
}
expected := string(expectedBytes)
stdout, err := runScriptFile(baseFilename+".toi", "", testCase.Stdin)
if err != nil {
t.Errorf("expected no error but got: %v", err)
t.Fail()
} else if stdout != expected {
t.Errorf("output not as expected; expected:\n###%s###\nactual:\n###%s###", expected, stdout)
t.Fail()
}
})
}
}