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

Function TestStringFormat

ext/formatting_test.go:35–1023  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 15

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

Tested by

no test coverage detected