| 801 | } |
| 802 | |
| 803 | func FuzzQuote(f *testing.F) { |
| 804 | tests := []string{ |
| 805 | "this is a test", |
| 806 | `only one quote"`, |
| 807 | `"only one quote`, |
| 808 | "first\nsecond", |
| 809 | "bell\a", |
| 810 | "\bbackspace", |
| 811 | "\fform feed", |
| 812 | "carriage \r return", |
| 813 | "horizontal \ttab", |
| 814 | "vertical \v tab", |
| 815 | "double \\\\ slash", |
| 816 | "two escape sequences \a\n", |
| 817 | "ends with \\", |
| 818 | "\\ starts with", |
| 819 | "printable unicode😀", |
| 820 | "mid-string \" quote", |
| 821 | "\\? and \\`", |
| 822 | "filler \x9f", |
| 823 | "size('ÿ')", |
| 824 | "size('πέντε')", |
| 825 | "завтра", |
| 826 | "\U0001F431\U0001F600\U0001F61B", |
| 827 | "ta©o©αT", |
| 828 | } |
| 829 | for _, tc := range tests { |
| 830 | f.Add(tc) |
| 831 | } |
| 832 | f.Fuzz(func(t *testing.T, s string) { |
| 833 | quoted, err := quote(s) |
| 834 | if err != nil { |
| 835 | if utf8.ValidString(s) { |
| 836 | t.Errorf("unexpected error: %s", err) |
| 837 | } |
| 838 | } else { |
| 839 | unquoted, err := unquote(quoted) |
| 840 | if err != nil { |
| 841 | t.Errorf("unexpected error: %s", err) |
| 842 | } else if s != sanitize(s) { |
| 843 | if unquoted != sanitize(s) { |
| 844 | t.Errorf("input-output mismatch on test case containing invalid UTF-8: sanitized original: %q, quoted: %q, quote/unquote: %q", sanitize(s), quoted, unquoted) |
| 845 | } |
| 846 | } else if unquoted != s { |
| 847 | t.Errorf("input-output mismatch: original: %q, quoted: %q, quote/unquote: %q", s, quoted, unquoted) |
| 848 | } |
| 849 | } |
| 850 | }) |
| 851 | } |
| 852 | |
| 853 | func TestStringCostTracking(t *testing.T) { |
| 854 | tests := []struct { |