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

Function TestStringCostTracking

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

Source from the content-addressed store, hash-verified

851}
852
853func TestStringCostTracking(t *testing.T) {
854 tests := []struct {
855 name string
856 expr string
857 estimatedCost checker.CostEstimate
858 actualCost uint64
859 }{
860 {
861 name: "charAt",
862 expr: `"hello world".charAt(0)`,
863 estimatedCost: checker.FixedCostEstimate(4),
864 actualCost: 4,
865 },
866 {
867 name: "indexOf",
868 expr: `"hello world".indexOf("world")`,
869 estimatedCost: checker.FixedCostEstimate(7),
870 actualCost: 7,
871 },
872 {
873 name: "lastIndexOf",
874 expr: `"hello world".lastIndexOf("o")`,
875 estimatedCost: checker.FixedCostEstimate(3),
876 actualCost: 3,
877 },
878 {
879 name: "lowerAscii",
880 expr: `"HELLO".lowerAscii()`,
881 estimatedCost: checker.FixedCostEstimate(7),
882 actualCost: 7,
883 },
884 {
885 name: "upperAscii",
886 expr: `"hello".upperAscii()`,
887 estimatedCost: checker.FixedCostEstimate(7),
888 actualCost: 7,
889 },
890 {
891 name: "replace",
892 expr: `"hello world".replace("world", "CEL")`,
893 estimatedCost: checker.CostEstimate{Min: 11, Max: 55},
894 actualCost: 16,
895 },
896 {
897 name: "replace_exponential_growth",
898 expr: `"A".replace("", "AAAAAAAAAA").replace("", "AAAAAAAAAA")`,
899 estimatedCost: checker.CostEstimate{Min: 6, Max: 281},
900 actualCost: 268,
901 },
902 {
903 name: "split",
904 expr: `"a,b,c,d,e".split(",")`,
905 estimatedCost: checker.CostEstimate{Min: 12, Max: 21},
906 actualCost: 17,
907 },
908 {
909 name: "substring",
910 expr: `"hello world".substring(0, 5)`,

Callers

nothing calls this directly

Calls 12

CompileMethod · 0.95
ProgramMethod · 0.95
FixedCostEstimateFunction · 0.92
NewEnvFunction · 0.92
CostTrackingFunction · 0.92
NoVarsFunction · 0.92
StringsFunction · 0.85
StringsVersionFunction · 0.85
testCheckCostFunction · 0.85
ErrMethod · 0.80
EvalMethod · 0.65
ActualCostMethod · 0.45

Tested by

no test coverage detected