-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathincr_decr_test.go
171 lines (152 loc) · 2.83 KB
/
incr_decr_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
169
170
171
package testing
import "testing"
func Test_Increment_Basic(t *testing.T) {
rsl := `
a = 1
a++
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "2\n")
assertNoErrors(t)
}
func Test_Increment_Loop(t *testing.T) {
rsl := `
a = 1
for i in range(1000):
a++
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "1001\n")
assertNoErrors(t)
}
func Test_Increment_InList(t *testing.T) {
rsl := `
a = [1, [2]]
a[1][0]++
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "[ 1, [ 3 ] ]\n")
assertNoErrors(t)
}
func Test_Increment_InMap(t *testing.T) {
rsl := `
a = {"a": 1, "b": {"c": 2}}
a.b.c++
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, `{ "a": 1, "b": { "c": 3 } }`+"\n")
assertNoErrors(t)
}
func Test_Decrement_Basic(t *testing.T) {
rsl := `
a = 10
a--
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "9\n")
assertNoErrors(t)
}
func Test_Decrement_Loop(t *testing.T) {
rsl := `
a = 10
for i in range(1000):
a--
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "-990\n")
assertNoErrors(t)
}
func Test_Decrement_InList(t *testing.T) {
rsl := `
a = [1, [2]]
a[1][0]--
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "[ 1, [ 1 ] ]\n")
assertNoErrors(t)
}
func Test_Decrement_InMap(t *testing.T) {
rsl := `
a = {"a": 1, "b": {"c": 2}}
a.b.c--
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, `{ "a": 1, "b": { "c": 1 } }`+"\n")
assertNoErrors(t)
}
func Test_Increment_CannotChain(t *testing.T) {
rsl := `
a = 1
a++++
`
setupAndRunCode(t, rsl, "--color=never")
expected := `Error at L3:1
a++++
^^^^^ Invalid syntax
`
assertError(t, 1, expected)
}
func Test_Decrement_CannotChain(t *testing.T) {
rsl := `
a = 1
a----
`
setupAndRunCode(t, rsl, "--color=never")
expected := `Error at L3:1
a----
^^^^^ Invalid syntax
`
assertError(t, 1, expected)
}
func Test_IncrDecr_CannotChain(t *testing.T) {
rsl := `
a = 1
a++--
`
setupAndRunCode(t, rsl, "--color=never")
expected := `Error at L3:1
a++--
^^^^^ Invalid syntax
`
assertError(t, 1, expected)
}
func Test_DecrIncr_CannotChain(t *testing.T) {
rsl := `
a = 1
a--++
`
setupAndRunCode(t, rsl, "--color=never")
expected := `Error at L3:1
a--++
^^^^^ Invalid syntax
`
assertError(t, 1, expected)
}
func Test_Increment_CanIncrementFloat(t *testing.T) {
rsl := `
a = 1.5
a++
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "2.5\n")
assertNoErrors(t)
}
func Test_Decrement_CanDecrementFloat(t *testing.T) {
rsl := `
a = 1.5
a--
print(a)
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "0.5\n")
assertNoErrors(t)
}