-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcherri_test.go
137 lines (116 loc) Β· 2.77 KB
/
cherri_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Copyright (c) Cherri
*/
package main
import (
"encoding/json"
"fmt"
"os"
"strings"
"testing"
"time"
"github.com/electrikmilk/args-parser"
)
var currentTest string
func TestCherri(_ *testing.T) {
args.Args["no-ansi"] = ""
var files, err = os.ReadDir("tests")
if err != nil {
fmt.Println(ansi("FAILED: unable to read tests directory", red))
panic(err)
}
for _, file := range files {
if !strings.Contains(file.Name(), ".cherri") {
continue
}
currentTest = fmt.Sprintf("tests/%s", file.Name())
os.Args[1] = currentTest
fmt.Println(ansi(currentTest, underline, bold))
compile()
fmt.Println(ansi("β
PASSED", green, bold))
fmt.Print("\n")
resetParser()
if signFailed {
fmt.Println(ansi("Using remote service HubSign", cyan, bold))
for i := 5; i > 0; i-- {
fmt.Print(ansi(fmt.Sprintf("Respectfully waiting %d second(s) between tests...\r", i), cyan))
time.Sleep(1 * time.Second)
}
fmt.Print("\n")
}
}
}
func TestCherriNoSign(t *testing.T) {
args.Args["skip-sign"] = ""
TestCherri(t)
}
func TestSingleFile(_ *testing.T) {
currentTest = "tests/conditionals.cherri"
fmt.Printf("βοΈ Compiling %s...\n", ansi(currentTest, bold))
os.Args[1] = currentTest
main()
fmt.Print(ansi("β
PASSED", green, bold) + "\n\n")
}
func TestDecomp(t *testing.T) {
fmt.Println("Decompiling...")
args.Args["import"] = "tests/decomp_me.plist"
decompile(importShortcut())
fmt.Println("Comparing to expected...")
var bytes, readErr = os.ReadFile("tests/decomp_expected.cherri")
handle(readErr)
if code.String() != string(bytes) {
fmt.Println(ansi("Does not match expected!", red, bold))
t.Fail()
return
}
fmt.Print(ansi("β
PASSED", green, bold) + "\n\n")
}
func TestActionList(_ *testing.T) {
for identifier := range actions {
fmt.Println("{label: '" + identifier + "', type: 'function', detail: 'action'},")
}
}
func TestGlyphList(_ *testing.T) {
var data, jsonErr = json.Marshal(glyphs)
handle(jsonErr)
fmt.Println(string(data))
}
func compile() {
defer func() {
if recover() != nil {
panicDebug(nil)
}
}()
main()
}
func resetParser() {
lines = []string{}
chars = []rune{}
char = -1
idx = 0
lineIdx = 0
lineCharIdx = -1
groupingUUIDs = map[int]string{}
groupingTypes = map[int]tokenType{}
groupingIdx = 0
variables = map[string]variableValue{}
iconColor = -1263359489
iconGlyph = 61440
clientVersion = "900"
iosVersion = 16.5
questions = map[string]*question{}
hasShortcutInputVariables = false
tabLevel = 0
types = []string{}
inputs = []string{}
outputs = []string{}
noInput = noInputParams{}
tokens = []token{}
included = []string{}
includes = []include{}
workflowName = ""
plist.Reset()
menus = map[string][]variableValue{}
uuids = map[string]string{}
customActions = map[string]*customAction{}
}