(t *testing.T)
| 851 | } |
| 852 | |
| 853 | func TestStringCostTracking(t *testing.T) { |
| 854 | tests := []struct { |
| 855 | name string |
| 856 | expr string |
| 857 | estimatedCost checker.CostEstimate |
| 858 | actualCost uint64 |
| 859 | }{ |
| 860 | { |
| 861 | name: "charAt", |
| 862 | expr: `"hello world".charAt(0)`, |
| 863 | estimatedCost: checker.FixedCostEstimate(4), |
| 864 | actualCost: 4, |
| 865 | }, |
| 866 | { |
| 867 | name: "indexOf", |
| 868 | expr: `"hello world".indexOf("world")`, |
| 869 | estimatedCost: checker.FixedCostEstimate(7), |
| 870 | actualCost: 7, |
| 871 | }, |
| 872 | { |
| 873 | name: "lastIndexOf", |
| 874 | expr: `"hello world".lastIndexOf("o")`, |
| 875 | estimatedCost: checker.FixedCostEstimate(3), |
| 876 | actualCost: 3, |
| 877 | }, |
| 878 | { |
| 879 | name: "lowerAscii", |
| 880 | expr: `"HELLO".lowerAscii()`, |
| 881 | estimatedCost: checker.FixedCostEstimate(7), |
| 882 | actualCost: 7, |
| 883 | }, |
| 884 | { |
| 885 | name: "upperAscii", |
| 886 | expr: `"hello".upperAscii()`, |
| 887 | estimatedCost: checker.FixedCostEstimate(7), |
| 888 | actualCost: 7, |
| 889 | }, |
| 890 | { |
| 891 | name: "replace", |
| 892 | expr: `"hello world".replace("world", "CEL")`, |
| 893 | estimatedCost: checker.CostEstimate{Min: 11, Max: 55}, |
| 894 | actualCost: 16, |
| 895 | }, |
| 896 | { |
| 897 | name: "replace_exponential_growth", |
| 898 | expr: `"A".replace("", "AAAAAAAAAA").replace("", "AAAAAAAAAA")`, |
| 899 | estimatedCost: checker.CostEstimate{Min: 6, Max: 281}, |
| 900 | actualCost: 268, |
| 901 | }, |
| 902 | { |
| 903 | name: "split", |
| 904 | expr: `"a,b,c,d,e".split(",")`, |
| 905 | estimatedCost: checker.CostEstimate{Min: 12, Max: 21}, |
| 906 | actualCost: 17, |
| 907 | }, |
| 908 | { |
| 909 | name: "substring", |
| 910 | expr: `"hello world".substring(0, 5)`, |
nothing calls this directly
no test coverage detected