forked from influxdata/flux
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scope.go
39 lines (35 loc) · 870 Bytes
/
scope.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
package valuestest
import (
"github.com/InfluxCommunity/flux/runtime"
"github.com/InfluxCommunity/flux/values"
"github.com/google/go-cmp/cmp"
)
// ComparableScope is a representation of a Scope
// that is easily compared with the cmp package.
type ComparableScope struct {
Values map[string]values.Value
Child *ComparableScope
}
// ScopeTransformer converts a scope to a ComparableScope.
var ScopeTransformer = cmp.Transformer("Scope", func(s values.Scope) *ComparableScope {
var sc *ComparableScope = nil
for {
if s != nil {
sc = &ComparableScope{
Values: make(map[string]values.Value),
Child: sc,
}
s.LocalRange(func(k string, v values.Value) {
sc.Values[k] = v
})
s = s.Pop()
} else {
break
}
}
return sc
})
// Scope returns a scope that contains the prelude.
func Scope() values.Scope {
return runtime.Prelude()
}