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