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

Function TestFunctionsForVersions

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

Source from the content-addressed store, hash-verified

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