Debian Codegraph @

ext/encoders_test.go

raw symbols SCIP
1 // Copyright 2020 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package extscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/
16
17 import (
18 "fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/"
19 "stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/"
20 "testingscip-go gomod github.com/golang/go/src go1.23.0 testing/"
21
22 "github.com/google/cel-go/celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/"
23 )
24
25 func TestEncodersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/TestEncoders().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
26 var tests = []struct {
27 expr string
28 err string
29 parseOnly bool
30 }{
31 {expr: "base64.decode('aGVsbG8=') == b'hello'"},
32 {expr: "base64.decode('aGVsbG8') == b'hello'"},
33 {
34 expr: "base64.decode(b'aGVsbG8=') == b'hello'",
35 err: "no such overload",
36 parseOnly: true,
37 },
38 {expr: "base64.encode(b'hello') == 'aGVsbG8='"},
39 {
40 expr: "base64.encode('hello') == b'aGVsbG8='",
41 err: "no such overload",
42 parseOnly: true,
43 },
44 }
45
46 env, err := celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.NewEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/NewEnv().(Encodersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/Encoders().())
47 if err != nil {
48 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("cel.NewEnv(Encoders()) failed: %v", err)
49 }
50 for i, tst := range tests {
51 tc := tst
52 t.Runscip-go gomod github.com/golang/go/src go1.23.0 testing/T#Run().(fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Sprintf().("[%d]", i), func(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
53 var asts []*celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.Astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Ast#
54 pAst, iss := env.Parsescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#Parse().(tc.expr)
55 if iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().() != nil {
56 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("env.Parse(%v) failed: %v", tc.expr, iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().())
57 }
58 asts = append(asts, pAst)
59 if !tc.parseOnly {
60 cAst, iss := env.Checkscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#Check().(pAst)
61 if iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().() != nil {
62 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("env.Check(%v) failed: %v", tc.expr, iss.Errscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Issues#Err().())
63 }
64 asts = append(asts, cAst)
65 }
66 for _, ast := range asts {
67 prg, err := env.Programscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Env#Program().(ast)
68 if err != nil {
69 t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err)
70 }
71 out, _, err := prg.Evalscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/Program#Eval.(celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.NoVarsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/NoVars().())
72 if tc.err != "" {
73 if err == nil {
74 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("got %v, wanted error %s for expr: %s",
75 out.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.(), tc.err, tc.expr)
76 }
77 if !stringsscip-go gomod github.com/golang/go/src go1.23.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.23.0 strings/Contains().(err.Error(), tc.err) {
78 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got error %v, wanted error %s for expr: %s", err, tc.err, tc.expr)
79 }
80 } else if err != nil {
81 t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().(err)
82 } else if out.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.() != true {
83 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("got %v, wanted true for expr: %s", out.Valuescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/ref`/Val#Value.(), tc.expr)
84 }
85 }
86 })
87 }
88 }
89
90 func TestEncodersVersionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/TestEncodersVersion().(t *testingscip-go gomod github.com/golang/go/src go1.23.0 testing/.Tscip-go gomod github.com/golang/go/src go1.23.0 testing/T#) {
91 _, err := celscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/.NewEnvscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/cel`/NewEnv().(Encodersscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/Encoders().(EncodersVersionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/ext`/EncodersVersion().(0)))
92 if err != nil {
93 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("EncodersVersion(0) failed: %v", err)
94 }
95 }