-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconstraint_enum_test.go
63 lines (54 loc) · 1.25 KB
/
constraint_enum_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
package testing
import "testing"
func Test_Constraint_Enum_Valid(t *testing.T) {
rsl := `
args:
name string
name enum ["alice", "bob", "charlie"]
print("Hi", name)
`
setupAndRunCode(t, rsl, "alice")
assertOnlyOutput(t, stdOutBuffer, "Hi alice\n")
assertNoErrors(t)
}
func Test_Constraint_Enum_ErrorsOnInvalid(t *testing.T) {
rsl := `
args:
name string
name enum ["alice", "bob", "charlie"]
print("Hi", name)
`
setupAndRunCode(t, rsl, "david", "--color=never")
expected := `Invalid 'name' value: david (valid values: alice, bob, charlie)
Usage:
<name>
Script args:
--name string Valid values: [alice, bob, charlie].
` + scriptGlobalFlagHelp
assertError(t, 1, expected)
}
func Test_Constraint_Enum_ErrorsIfNonStringEnum(t *testing.T) {
rsl := `
args:
name string
name enum ["alice", 2]
print("Hi", name)
`
setupAndRunCode(t, rsl, "david", "--color=never")
expected := `Error at L4:25
name enum ["alice", 2]
^ Invalid syntax
`
assertError(t, 1, expected)
}
func Test_Constraint_Enum_CanHaveArgNamedEnum(t *testing.T) {
rsl := `
args:
enum string
enum enum ["alice", "bob", "charlie"]
print("Hi", enum)
`
setupAndRunCode(t, rsl, "alice")
assertOnlyOutput(t, stdOutBuffer, "Hi alice\n")
assertNoErrors(t)
}