-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunc_join_test.go
78 lines (72 loc) · 1.56 KB
/
func_join_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
package testing
import "testing"
func Test_Join_String(t *testing.T) {
rsl := `
arr = ["Hi", "there"]
print(join(arr, " "))
print(join(arr, " ", "Alice: "))
print(join(arr, " ", "Alice: ", "!"))
`
setupAndRunCode(t, rsl, "--color=never")
expected := `Hi there
Alice: Hi there
Alice: Hi there!
`
assertOnlyOutput(t, stdOutBuffer, expected)
assertNoErrors(t)
}
func Test_Join_Int(t *testing.T) {
rsl := `
arr = [1, 2, 3]
print(join(arr, "_"))
print(join(arr, "_", "Nums: "))
print(join(arr, "_", "Nums: ", "_4"))
`
setupAndRunCode(t, rsl, "--color=never")
expected := `1_2_3
Nums: 1_2_3
Nums: 1_2_3_4
`
assertOnlyOutput(t, stdOutBuffer, expected)
assertNoErrors(t)
}
func Test_Join_Float(t *testing.T) {
rsl := `
arr = [1.1, 1.2, 1.3]
print(join(arr, " yes "))
print(join(arr, " yes ", "Floats: "))
print(join(arr, " yes ", "Floats: ", " :D"))
`
setupAndRunCode(t, rsl, "--color=never")
expected := `1.1 yes 1.2 yes 1.3
Floats: 1.1 yes 1.2 yes 1.3
Floats: 1.1 yes 1.2 yes 1.3 :D
`
assertOnlyOutput(t, stdOutBuffer, expected)
assertNoErrors(t)
}
func Test_Join_Mixed(t *testing.T) {
rsl := `
arr = ["alice", 2]
print(join(arr, "_"))
print(join(arr, "_", "("))
print(join(arr, "_", "(", ")"))
`
setupAndRunCode(t, rsl, "--color=never")
expected := `alice_2
(alice_2
(alice_2)
`
assertOnlyOutput(t, stdOutBuffer, expected)
assertNoErrors(t)
}
func Test_Join_ReturnsRslString(t *testing.T) {
rsl := `
print(type_of(join(["Hi", "!"], "")))
`
setupAndRunCode(t, rsl, "--color=never")
expected := `string
`
assertOnlyOutput(t, stdOutBuffer, expected)
assertNoErrors(t)
}