-
Notifications
You must be signed in to change notification settings - Fork 152
/
complete_test.go
101 lines (86 loc) · 2.05 KB
/
complete_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
package complete_test
import (
"context"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/influxdata/flux/complete"
"github.com/influxdata/flux/semantic"
"github.com/influxdata/flux/values"
)
func TestNames(t *testing.T) {
s := values.NewScope()
v := values.NewInt(0)
s.Set("boom", v)
s.Set("tick", v)
c := complete.NewCompleter(s)
results := c.Names()
expected := []string{
"boom",
"tick",
}
if !cmp.Equal(results, expected) {
t.Error(cmp.Diff(results, expected), "unexpected names from declarations")
}
}
func TestValue(t *testing.T) {
name := "foo"
scope := values.NewScope()
value := values.NewInt(5)
scope.Set(name, value)
v, _ := complete.NewCompleter(scope).Value(name)
if !cmp.Equal(value, v) {
t.Error(cmp.Diff(value, v), "unexpected value for name")
}
}
func TestFunctionNames(t *testing.T) {
boom := values.NewFunction(
"boom",
semantic.NewFunctionType(semantic.BasicInt, nil),
func(context.Context, values.Object) (values.Value, error) {
return values.NewInt(5), nil
},
false,
)
s := values.NewScope()
s.Set("boom", boom)
c := complete.NewCompleter(s)
results := c.FunctionNames()
expected := []string{
"boom",
}
if !cmp.Equal(results, expected) {
t.Error(cmp.Diff(results, expected), "unexpected function names")
}
}
func TestFunctionSuggestion(t *testing.T) {
name := "bar"
bar := values.NewFunction(
name,
semantic.NewFunctionType(semantic.BasicInt, []semantic.ArgumentType{
{
Name: []byte("start"),
Type: semantic.BasicTime,
},
{
Name: []byte("stop"),
Type: semantic.BasicTime,
},
}),
func(context.Context, values.Object) (values.Value, error) {
return values.NewInt(5), nil
},
false,
)
s := values.NewScope()
s.Set(name, bar)
result, _ := complete.NewCompleter(s).FunctionSuggestion(name)
expected := complete.FunctionSuggestion{
Params: map[string]string{
"start": semantic.Time.String(),
"stop": semantic.Time.String(),
},
}
if !cmp.Equal(result, expected) {
t.Error(cmp.Diff(result, expected), "does not match expected suggestion")
}
}