-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunc_clamp_test.go
57 lines (49 loc) · 1.2 KB
/
func_clamp_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
package testing
import "testing"
func Test_Func_Clamp_Ints(t *testing.T) {
rsl := `
print(clamp(1, 0, 2))
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "1\n")
assertNoErrors(t)
}
func Test_Func_Clamp_Mix(t *testing.T) {
rsl := `
print(clamp(2.2, 1.2, 2))
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "2\n")
assertNoErrors(t)
}
func Test_Func_Clamp_ErrorsForLessThan3Elements(t *testing.T) {
rsl := `
print(clamp(1, 2))
`
setupAndRunCode(t, rsl, "--color=never")
expected := `Error at L2:7
print(clamp(1, 2))
^^^^^^^^^^^ clamp() requires at least 3 arguments, but got 2
`
assertError(t, 1, expected)
}
func Test_Func_Clamp_ErrorsForNonNumElements(t *testing.T) {
rsl := `
print(clamp(1, "ab", 2))
`
setupAndRunCode(t, rsl, "--color=never")
expected := `Error at L2:16
print(clamp(1, "ab", 2))
^^^^
Got "string" as the 2nd argument of clamp(), but must be: float or int
`
assertError(t, 1, expected)
}
func Test_Func_Clamp_Negative(t *testing.T) {
rsl := `
print(clamp(-2.2, -1.2, 2))
`
setupAndRunCode(t, rsl, "--color=never")
assertOnlyOutput(t, stdOutBuffer, "-1.2\n")
assertNoErrors(t)
}