-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval_test.go
70 lines (60 loc) · 1.23 KB
/
eval_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"encoding/json"
"fmt"
"log"
"os"
"os/exec"
"strings"
"testing"
)
func TestExamples(t *testing.T) {
files, _ := os.ReadDir("examples")
for _, file := range files {
fileName := file.Name()
t.Log(fileName)
if !strings.Contains(fileName, ".rinha.json") {
rinhaToJson(fileName)
continue
}
}
files, _ = os.ReadDir("examples")
for _, file := range files {
fileName := file.Name()
t.Log(fileName)
if !strings.Contains(fileName, ".rinha.json") {
continue
}
stdin, err := os.ReadFile("examples/" + fileName)
if err != nil {
panic(err)
}
var ast File
if err := json.Unmarshal(stdin, &ast); err != nil {
fmt.Println(stdin)
t.Error("Error decoding JSON:", err)
return
}
SCOPE_DEFAULT_SIZE := 8
scope := make(Scope, SCOPE_DEFAULT_SIZE)
t.Log(">>>>>>>>>>>> ", fileName)
Eval(scope, ast.Expression)
t.Log()
}
}
func rinhaToJson(fileName string) {
cmd := exec.Command("rinha", fmt.Sprintf("examples/%s", fileName))
value, err := cmd.Output()
if err != nil {
log.Fatal(err)
}
f, err := os.Create(fmt.Sprintf("examples/%s.json", fileName))
if err != nil {
log.Fatal(err)
}
a, err := f.WriteString(string(value))
if err != nil {
log.Fatal(a, err)
}
f.Sync()
}