TestTokenizeContext_ErrorHandling verifies proper error handling
(t *testing.T)
| 187 | |
| 188 | // TestTokenizeContext_ErrorHandling verifies proper error handling |
| 189 | func TestTokenizeContext_ErrorHandling(t *testing.T) { |
| 190 | tests := []struct { |
| 191 | name string |
| 192 | input string |
| 193 | shouldError bool |
| 194 | }{ |
| 195 | { |
| 196 | name: "unterminated string", |
| 197 | input: "SELECT 'unterminated", |
| 198 | shouldError: true, |
| 199 | }, |
| 200 | { |
| 201 | name: "invalid character", |
| 202 | input: "SELECT \x00 FROM users", |
| 203 | shouldError: true, |
| 204 | }, |
| 205 | } |
| 206 | |
| 207 | for _, tt := range tests { |
| 208 | t.Run(tt.name, func(t *testing.T) { |
| 209 | ctx := context.Background() |
| 210 | tkz := GetTokenizer() |
| 211 | defer PutTokenizer(tkz) |
| 212 | |
| 213 | tokens, err := tkz.TokenizeContext(ctx, []byte(tt.input)) |
| 214 | |
| 215 | if tt.shouldError && err == nil { |
| 216 | t.Error("Expected error but got none") |
| 217 | } |
| 218 | |
| 219 | if err != nil && err == context.Canceled { |
| 220 | t.Error("Should not return context.Canceled for SQL errors") |
| 221 | } |
| 222 | |
| 223 | if tt.shouldError && tokens != nil { |
| 224 | t.Error("Expected nil tokens on error") |
| 225 | } |
| 226 | }) |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | // TestTokenizeContext_CancellationResponseTime verifies fast cancellation (< 100ms requirement) |
| 231 | func TestTokenizeContext_CancellationResponseTime(t *testing.T) { |
nothing calls this directly
no test coverage detected