-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathslice_string_test.go
100 lines (91 loc) · 1.92 KB
/
slice_string_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
package testing
import "testing"
func TestSlice_String_Basic(t *testing.T) {
rsl := `
a = "alice"
print(a[0:2])
print(a[1:3])
print(a[3:4])
print(a[0:len(a)])
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "al\nli\nc\nalice\n")
assertNoErrors(t)
}
func TestSlice_String_Negative(t *testing.T) {
rsl := `
a = "alice"
print(a[-5:-3])
print(a[-4:-2])
print(a[-2:-1])
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "al\nli\nc\n")
assertNoErrors(t)
}
func TestSlice_String_PositiveAndNegative(t *testing.T) {
rsl := `
a = "alice"
print(a[-3:3])
print(a[-2:2])
print(a[1:-1])
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "i\n\nlic\n")
assertNoErrors(t)
}
func TestSlice_String_NoStartEndReturnsWholeString(t *testing.T) {
rsl := `
a = "alice"
print(a[:])
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "alice\n")
assertNoErrors(t)
}
func TestSlice_String_OkayOutsideBounds(t *testing.T) {
rsl := `
a = "alice"
print(a[0:99])
print(a[-99:-1])
print(a[-99:99])
print(a[:99])
print(a[-99:])
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "alice\nalic\nalice\nalice\nalice\n")
assertNoErrors(t)
}
func TestSlice_String_EmptySlices(t *testing.T) {
rsl := `
a = "alice"
print(a[0:0])
print(a[3:3])
print(a[-3:-3])
print(a[99:])
print(a[:-99])
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "\n\n\n\n\n")
assertNoErrors(t)
}
func TestSlice_String_PartialSlices(t *testing.T) {
rsl := `
a = "alice"
print(a[2:])
print(a[:-2])
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "ice\nali\n")
assertNoErrors(t)
}
func TestSlice_String_DoesNotErrorOnNonsenseSlices(t *testing.T) {
rsl := `
a = "alice"
print(a[3:2])
print(a[-2:-3])
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "\n\n")
assertNoErrors(t)
}