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

Function TestStringCostTracking

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 14

CompileMethod · 0.95
ProgramMethod · 0.95
FixedCostEstimateFunction · 0.92
RangedCostEstimateFunction · 0.92
NewEnvFunction · 0.92
CostTrackingFunction · 0.92
NoVarsFunction · 0.92
StringsFunction · 0.85
StringsVersionFunction · 0.85
testCheckCostFunction · 0.85
ErrMethod · 0.80
costV0Function · 0.70

Tested by

no test coverage detected