(t *testing.T)
| 33 | ) |
| 34 | |
| 35 | func 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, |
nothing calls this directly
no test coverage detected