(t *testing.T)
| 44 | } |
| 45 | |
| 46 | func 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}, |
nothing calls this directly
no test coverage detected