-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathternary_test.go
168 lines (146 loc) · 3.27 KB
/
ternary_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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package testing
import "testing"
func Test_Ternary_True(t *testing.T) {
rsl := `
a = "alice"
print(true ? a : "bob")
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "alice\n")
assertNoErrors(t)
}
func Test_Ternary_False(t *testing.T) {
rsl := `
a = "alice"
print(false ? a : "bob")
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "bob\n")
assertNoErrors(t)
}
func Test_Ternary_Nested(t *testing.T) {
rsl := `
print(true ? (false ? "bob" : "charlie") : "alice")
print(true ? false ? "bob" : "charlie" : "alice")
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "charlie\ncharlie\n")
assertNoErrors(t)
}
func Test_Ternary_Complex(t *testing.T) {
t.Skip("TODO RAD-142") // TODO RAD-142
rsl := `
a = 5
b = "alice"
c = "charlie"
print((c[0] == 'c' ? c : b)[(len(b) > 3 ? 1 : 2):5])
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "harl\n")
assertNoErrors(t)
}
func Test_Ternary_Truthy(t *testing.T) {
rsl := `
a = "not empty"
print(a ? a : "empty")
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "not empty\n")
assertNoErrors(t)
}
func Test_Ternary_Falsy(t *testing.T) {
rsl := `
a = ""
print(a ? a : "empty")
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "empty\n")
assertNoErrors(t)
}
func Test_Ternary_CanDefineAcrossLines1(t *testing.T) {
t.Skip("TODO RAD-140") // TODO RAD-140
rsl := `
a = "blah"
? "not empty"
: "empty"
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "not empty\n")
assertNoErrors(t)
}
func Test_Ternary_CanDefineAcrossLines2(t *testing.T) {
rsl := `
a = "blah" ? "not empty"
: "empty"
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "not empty\n")
assertNoErrors(t)
}
func Test_Ternary_CanDefineAcrossLines3(t *testing.T) {
t.Skip("TODO RAD-140") // TODO RAD-140
rsl := `
a = "blah"
? "not empty" : "empty"
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "not empty\n")
assertNoErrors(t)
}
func Test_Ternary_CanDefineAcrossLines4(t *testing.T) {
t.Skip("TODO RAD-140") // TODO RAD-140
rsl := `
a = "blah"
?
"not empty" : "empty"
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "not empty\n")
assertNoErrors(t)
}
func Test_Ternary_CanDefineAcrossLines5(t *testing.T) {
t.Skip("TODO RAD-140") // TODO RAD-140
rsl := `
a = "blah"
?
"not empty" :
"empty"
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "not empty\n")
assertNoErrors(t)
}
func Test_Ternary_CanDefineAcrossLines6BigSpace(t *testing.T) {
t.Skip("TODO RAD-140") // TODO RAD-140
rsl := `
a = "blah"
?
"not empty" :
"empty"
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "not empty\n")
assertNoErrors(t)
}
func Test_Ternary_FailsIfWhitespaceAbused(t *testing.T) {
rsl := `
if true:
a = "blah"
? "not empty" : "empty"
print("one")
print("two")
`
setupAndRunCode(t, rsl, "--color=never")
// this specific error is not ideal, we can (and probably should) improve it
expected := `Error at L3:12
a = "blah"
Invalid syntax
`
assertError(t, 1, expected)
}