diff options
Diffstat (limited to '')
| -rw-r--r-- | query.zig | 44 |
1 files changed, 19 insertions, 25 deletions
| @@ -64,7 +64,7 @@ pub const ParsedQuery = struct { | |||
| 64 | state = .BindMarkerType; | 64 | state = .BindMarkerType; |
| 65 | }, | 65 | }, |
| 66 | else => { | 66 | else => { |
| 67 | if (std.ascii.isAlpha(c) or std.ascii.isDigit(c)){ | 67 | if (std.ascii.isAlpha(c) or std.ascii.isDigit(c)) { |
| 68 | state = .BindMarkerIdentifier; | 68 | state = .BindMarkerIdentifier; |
| 69 | current_bind_marker_id[current_bind_marker_id_pos] = c; | 69 | current_bind_marker_id[current_bind_marker_id_pos] = c; |
| 70 | current_bind_marker_id_pos += 1; | 70 | current_bind_marker_id_pos += 1; |
| @@ -86,12 +86,12 @@ pub const ParsedQuery = struct { | |||
| 86 | current_bind_marker_type_pos = 0; | 86 | current_bind_marker_type_pos = 0; |
| 87 | 87 | ||
| 88 | // A bind marker with id and type: ?AAA{[]const u8}, we don't need move the pointer. | 88 | // A bind marker with id and type: ?AAA{[]const u8}, we don't need move the pointer. |
| 89 | if (current_bind_marker_id_pos > 0){ | 89 | if (current_bind_marker_id_pos > 0) { |
| 90 | parsed_query.bind_markers[parsed_query.nb_bind_markers].identifier = std.fmt.comptimePrint("{s}", .{current_bind_marker_id[0..current_bind_marker_id_pos]}); | 90 | parsed_query.bind_markers[parsed_query.nb_bind_markers].identifier = std.fmt.comptimePrint("{s}", .{current_bind_marker_id[0..current_bind_marker_id_pos]}); |
| 91 | } | 91 | } |
| 92 | }, | 92 | }, |
| 93 | else => { | 93 | else => { |
| 94 | if (std.ascii.isAlpha(c) or std.ascii.isDigit(c)){ | 94 | if (std.ascii.isAlpha(c) or std.ascii.isDigit(c)) { |
| 95 | current_bind_marker_id[current_bind_marker_id_pos] = c; | 95 | current_bind_marker_id[current_bind_marker_id_pos] = c; |
| 96 | current_bind_marker_id_pos += 1; | 96 | current_bind_marker_id_pos += 1; |
| 97 | } else { | 97 | } else { |
| @@ -313,28 +313,22 @@ test "parsed query: bind markers identifier type" { | |||
| 313 | expected_marker: BindMarker, | 313 | expected_marker: BindMarker, |
| 314 | }; | 314 | }; |
| 315 | 315 | ||
| 316 | const testCases = &[_]testCase{ | 316 | const testCases = &[_]testCase{ .{ |
| 317 | .{ | 317 | .query = "foobar @ABC{usize}", |
| 318 | .query = "foobar @ABC{usize}", | 318 | .expected_marker = .{ .id_type = .String }, |
| 319 | .expected_marker = .{ .id_type = .String }, | 319 | }, .{ |
| 320 | }, | 320 | .query = "foobar ?123{text}", |
| 321 | .{ | 321 | .expected_marker = .{ .id_type = .Integer }, |
| 322 | .query = "foobar ?123{text}", | 322 | }, .{ |
| 323 | .expected_marker = .{ .id_type = .Integer }, | 323 | .query = "foobar $abc{blob}", |
| 324 | }, | 324 | .expected_marker = .{ .id_type = .String }, |
| 325 | .{ | 325 | }, .{ |
| 326 | .query = "foobar $abc{blob}", | 326 | .query = "foobar ?123", |
| 327 | .expected_marker = .{ .id_type = .String }, | 327 | .expected_marker = .{ .id_type = .Integer }, |
| 328 | }, | 328 | }, .{ |
| 329 | .{ | 329 | .query = "foobar :abc", |
| 330 | .query = "foobar ?123", | 330 | .expected_marker = .{ .id_type = .String }, |
| 331 | .expected_marker = .{ .id_type = .Integer }, | 331 | } }; |
| 332 | }, | ||
| 333 | .{ | ||
| 334 | .query = "foobar :abc", | ||
| 335 | .expected_marker = .{ .id_type = .String }, | ||
| 336 | } | ||
| 337 | }; | ||
| 338 | 332 | ||
| 339 | inline for (testCases) |tc| { | 333 | inline for (testCases) |tc| { |
| 340 | comptime var parsed_query = ParsedQuery.from(tc.query); | 334 | comptime var parsed_query = ParsedQuery.from(tc.query); |