MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestFunctionsForVersions

Function TestFunctionsForVersions

ext/strings_test.go:753–801  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

751}
752
753func TestFunctionsForVersions(t *testing.T) {
754 tests := []struct {
755 version uint32
756 introducedFunctions []string
757 }{
758 {
759 version: 0,
760 introducedFunctions: []string{"lastIndexOf", "lowerAscii", "split", "trim", "join", "charAt", "indexOf", "replace", "substring", "upperAscii"},
761 },
762 {
763 version: 1,
764 introducedFunctions: []string{"strings.quote", "format"},
765 },
766 {
767 version: 2,
768 introducedFunctions: []string{}, // join changed, no functions added
769 },
770 {
771 version: 3,
772 introducedFunctions: []string{"reverse"},
773 },
774 }
775 var functions []string
776 for _, tt := range tests {
777 functions = append(functions, tt.introducedFunctions...)
778 t.Run(fmt.Sprintf("version %d", tt.version), func(t *testing.T) {
779 e, err := cel.NewCustomEnv(Strings(StringsVersion(tt.version)))
780 if err != nil {
781 t.Fatalf("NewEnv() failed: %v", err)
782 }
783 if len(functions) != len(e.Functions()) {
784 var functionNames []string
785 for name := range e.Functions() {
786 functionNames = append(functionNames, name)
787 }
788 t.Fatalf("Expected functions: %#v, got %#v", functions, functionNames)
789 }
790 for _, expected := range functions {
791 if !e.HasFunction(expected) {
792 t.Errorf("Expected HasFunction() to return true for '%s'", expected)
793 }
794
795 if _, ok := e.Functions()[expected]; !ok {
796 t.Errorf("Expected Functions() to include '%s'", expected)
797 }
798 }
799 })
800 }
801}
802
803func FuzzQuote(f *testing.F) {
804 tests := []string{

Callers

nothing calls this directly

Calls 5

NewCustomEnvFunction · 0.92
StringsFunction · 0.85
StringsVersionFunction · 0.85
FunctionsMethod · 0.80
HasFunctionMethod · 0.80

Tested by

no test coverage detected