Debian Codegraph @

parser/macro_test.go

raw symbols SCIP
1 // Copyright 2025 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 parserscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/
16
17 import (
18 "testingscip-go gomod github.com/golang/go/src go1.23.0 testing/"
19
20 "github.com/google/cel-go/commonscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/"
21 "github.com/google/cel-go/common/astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/"
22 )
23
24 func TestReceiverVarArgMacroscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/TestReceiverVarArgMacro().(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#) {
25 noopExpander := func(meh ExprHelperscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/ExprHelper#, target astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#, args []astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#) (astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#, *commonscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/.Errorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Error#) {
26 return nil, nil
27 }
28 varArgMacro := NewReceiverVarArgMacroscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/NewReceiverVarArgMacro().("varargs", noopExpander,
29 MacroDocsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/MacroDocs().(`convert variable argument lists to a list literal`),
30 MacroExamplesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/MacroExamples().(`varargs(1,2,3) // [1, 2, 3]`))
31 if varArgMacro.ArgCountscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#ArgCount.() != 0 {
32 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("ArgCount() got %d, wanted 0", varArgMacro.ArgCountscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#ArgCount.())
33 }
34 if varArgMacro.Functionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#Function.() != "varargs" {
35 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Function() got %q, wanted 'varargs'", varArgMacro.Functionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#Function.())
36 }
37 if varArgMacro.MacroKeyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#MacroKey.() != "varargs:*:true" {
38 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("MacroKey() got %q, wanted 'varargs:*:true'", varArgMacro.MacroKeyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#MacroKey.())
39 }
40 if !varArgMacro.IsReceiverStylescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#IsReceiverStyle.() {
41 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("IsReceiverStyle() got %t, wanted true", varArgMacro.IsReceiverStylescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#IsReceiverStyle.())
42 }
43 }
44
45 func TestDocumentationscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/TestDocumentation().(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#) {
46 noopExpander := func(meh ExprHelperscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/ExprHelper#, target astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#, args []astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#) (astscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/.Exprscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/ast`/Expr#, *commonscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/.Errorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Error#) {
47 return nil, nil
48 }
49 varArgMacro := NewReceiverVarArgMacroscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/NewReceiverVarArgMacro().("varargs", noopExpander,
50 MacroDocsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/MacroDocs().(`convert variable argument lists to a list literal`),
51 MacroExamplesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/MacroExamples().(`varargs(1,2,3) // [1, 2, 3]`))
52 doc, ok := varArgMacro.(commonscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/.Documentorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Documentor#)
53 if !ok {
54 t.Fatalscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatal().("macro does not implement Documenter interface")
55 }
56 d := doc.Documentationscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Documentor#Documentation.()
57 if d.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Doc#Kind. != commonscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/.DocMacroscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/DocMacro. {
58 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Documentation() got kind %v, wanted DocMacro", d.Kindscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Doc#Kind.)
59 }
60 if d.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Doc#Name. != varArgMacro.Functionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#Function.() {
61 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Documentation() got name %q, wanted %q", d.Namescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Doc#Name., varArgMacro.Functionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/parser`/Macro#Function.())
62 }
63 if d.Descriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Doc#Description. != `convert variable argument lists to a list literal` {
64 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("Documentation() got description %q, wanted %q", d.Descriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Doc#Description., `convert variable argument lists to a list literal`)
65 }
66 if len(d.Childrenscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Doc#Children.) != 1 {
67 t.Fatalfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Fatalf().("macro documentation children got: %d", len(d.Childrenscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Doc#Children.))
68 }
69 if d.Childrenscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Doc#Children.[0].Descriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Doc#Description. != `varargs(1,2,3) // [1, 2, 3]` {
70 t.Errorfscip-go gomod github.com/golang/go/src go1.23.0 testing/common#Errorf().("macro documentation Children[0] got %s, wanted %s", d.Childrenscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Doc#Children.[0].Descriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common`/Doc#Description., `varargs(1,2,3) // [1, 2, 3]`)
71 }
72 }