(t *testing.T)
| 119 | } |
| 120 | |
| 121 | func TestEscapeBackslash(t *testing.T) { |
| 122 | expect := func(expected, value string) { |
| 123 | actual := string(escapeBytesBackslash([]byte{}, []byte(value), false)) |
| 124 | if actual != expected { |
| 125 | t.Errorf( |
| 126 | "expected %s, got %s", |
| 127 | expected, actual, |
| 128 | ) |
| 129 | } |
| 130 | |
| 131 | actual = string(escapeStringBackslash([]byte{}, value)) |
| 132 | if actual != expected { |
| 133 | t.Errorf( |
| 134 | "expected %s, got %s", |
| 135 | expected, actual, |
| 136 | ) |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | expect("'foo\\0bar'", "foo\x00bar") |
| 141 | expect("'foo\\nbar'", "foo\nbar") |
| 142 | expect("'foo\\rbar'", "foo\rbar") |
| 143 | expect("'foo\\Zbar'", "foo\x1abar") |
| 144 | expect("'foo\\\"bar'", "foo\"bar") |
| 145 | expect("'foo\\\\bar'", "foo\\bar") |
| 146 | expect("'foo\\'bar'", "foo'bar") |
| 147 | |
| 148 | // Test binary flag for escapeBytesBackslash |
| 149 | binExpect := func(expected, value string) { |
| 150 | actual := string(escapeBytesBackslash([]byte{}, []byte(value), true)) |
| 151 | if actual != expected { |
| 152 | t.Errorf( |
| 153 | "expected %s, got %s (binary)", |
| 154 | expected, actual, |
| 155 | ) |
| 156 | } |
| 157 | } |
| 158 | binExpect("_binary'foo\\0bar'", "foo\x00bar") |
| 159 | binExpect("_binary'foo\\nbar'", "foo\nbar") |
| 160 | binExpect("_binary'foo\\rbar'", "foo\rbar") |
| 161 | binExpect("_binary'foo\\Zbar'", "foo\x1abar") |
| 162 | binExpect("_binary'foo\\\"bar'", "foo\"bar") |
| 163 | binExpect("_binary'foo\\\\bar'", "foo\\bar") |
| 164 | binExpect("_binary'foo\\'bar'", "foo'bar") |
| 165 | } |
| 166 | |
| 167 | func TestEscapeQuotes(t *testing.T) { |
| 168 | expect := func(expected, value string) { |
nothing calls this directly
no test coverage detected