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

Function TestStringFormatV2

ext/formatting_v2_test.go:46–1028  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

44}
45
46func TestStringFormatV2(t *testing.T) {
47 tests := []struct {
48 name string
49 format string
50 dynArgs map[string]any
51 formatArgs string
52 err string
53 expectedOutput string
54 expectedRuntimeCost uint64
55 expectedEstimatedCost checker.CostEstimate
56 skipCompileCheck bool
57 }{
58 {
59 name: "no-op",
60 format: "no substitution",
61 expectedOutput: "no substitution",
62 expectedRuntimeCost: 12,
63 expectedEstimatedCost: checker.CostEstimate{Min: 12, Max: 12},
64 },
65
66 {
67 name: "mid-string substitution",
68 format: "str is %s and some more",
69 formatArgs: `"filler"`,
70 expectedOutput: "str is filler and some more",
71 expectedRuntimeCost: 13,
72 expectedEstimatedCost: checker.CostEstimate{Min: 13, Max: 13},
73 },
74 {
75 name: "percent escaping",
76 format: "%% and also %%",
77 expectedOutput: "% and also %",
78 expectedRuntimeCost: 12,
79 expectedEstimatedCost: checker.CostEstimate{Min: 12, Max: 12},
80 },
81 {
82 name: "substution inside escaped percent signs",
83 format: "%%%s%%",
84 formatArgs: `"text"`,
85 expectedOutput: "%text%",
86 expectedRuntimeCost: 11,
87 expectedEstimatedCost: checker.CostEstimate{Min: 11, Max: 11},
88 },
89 {
90 name: "substitution with one escaped percent sign on the right",
91 format: "%s%%",
92 formatArgs: `"percent on the right"`,
93 expectedOutput: "percent on the right%",
94 expectedRuntimeCost: 11,
95 expectedEstimatedCost: checker.CostEstimate{Min: 11, Max: 11},
96 },
97 {
98 name: "substitution with one escaped percent sign on the left",
99 format: "%%%s",
100 formatArgs: `"percent on the left"`,
101 expectedOutput: "%percent on the left",
102 expectedRuntimeCost: 11,
103 expectedEstimatedCost: checker.CostEstimate{Min: 11, Max: 11},

Callers

nothing calls this directly

Calls 15

ParseMethod · 0.95
CheckMethod · 0.95
ProgramMethod · 0.95
EstimateCostMethod · 0.95
ActualCostMethod · 0.95
FixedCostEstimateFunction · 0.92
CostTrackingFunction · 0.92
NoVarsFunction · 0.92
VariableFunction · 0.92
ContainerFunction · 0.92
AbbrevsFunction · 0.92
TypesFunction · 0.92

Tested by

no test coverage detected