| ... | @@ -4203,7 +4203,7 @@ test "zig fmt: integer literals with underscore separators" { | ... | @@ -4203,7 +4203,7 @@ test "zig fmt: integer literals with underscore separators" { |
| 4203 | \\const | 4203 | \\const |
| 4204 | \\ x = | 4204 | \\ x = |
| 4205 | \\ 1_234_567 | 4205 | \\ 1_234_567 |
| 4206 | \\ +(0b0_1-0o7_0+0xff_FF ) + 0_0; | 4206 | \\ + (0b0_1-0o7_0+0xff_FF ) + 0_0; |
| 4207 | , | 4207 | , |
| 4208 | \\const x = | 4208 | \\const x = |
| 4209 | \\ 1_234_567 + (0b0_1 - 0o7_0 + 0xff_FF) + 0_0; | 4209 | \\ 1_234_567 + (0b0_1 - 0o7_0 + 0xff_FF) + 0_0; |
| ... | @@ -5105,7 +5105,7 @@ test "recovery: missing comma" { | ... | @@ -5105,7 +5105,7 @@ test "recovery: missing comma" { |
| 5105 | \\ 2 => {} | 5105 | \\ 2 => {} |
| 5106 | \\ 3 => {} | 5106 | \\ 3 => {} |
| 5107 | \\ else => { | 5107 | \\ else => { |
| 5108 | \\ foo && bar +; | 5108 | \\ foo & bar +; |
| 5109 | \\ } | 5109 | \\ } |
| 5110 | \\ } | 5110 | \\ } |
| 5111 | \\} | 5111 | \\} |
| ... | @@ -5139,7 +5139,7 @@ test "recovery: extra qualifier" { | ... | @@ -5139,7 +5139,7 @@ test "recovery: extra qualifier" { |
| 5139 | test "recovery: missing return type" { | 5139 | test "recovery: missing return type" { |
| 5140 | try testError( | 5140 | try testError( |
| 5141 | \\fn foo() { | 5141 | \\fn foo() { |
| 5142 | \\ a && b; | 5142 | \\ a & b; |
| 5143 | \\} | 5143 | \\} |
| 5144 | \\test "" | 5144 | \\test "" |
| 5145 | , &[_]Error{ | 5145 | , &[_]Error{ |
| ... | @@ -5154,7 +5154,7 @@ test "recovery: continue after invalid decl" { | ... | @@ -5154,7 +5154,7 @@ test "recovery: continue after invalid decl" { |
| 5154 | \\ inline; | 5154 | \\ inline; |
| 5155 | \\} | 5155 | \\} |
| 5156 | \\pub test "" { | 5156 | \\pub test "" { |
| 5157 | \\ async a && b; | 5157 | \\ async a & b; |
| 5158 | \\} | 5158 | \\} |
| 5159 | , &[_]Error{ | 5159 | , &[_]Error{ |
| 5160 | .expected_token, | 5160 | .expected_token, |
| ... | @@ -5163,7 +5163,7 @@ test "recovery: continue after invalid decl" { | ... | @@ -5163,7 +5163,7 @@ test "recovery: continue after invalid decl" { |
| 5163 | }); | 5163 | }); |
| 5164 | try testError( | 5164 | try testError( |
| 5165 | \\threadlocal test "" { | 5165 | \\threadlocal test "" { |
| 5166 | \\ @a && b; | 5166 | \\ @a & b; |
| 5167 | \\} | 5167 | \\} |
| 5168 | , &[_]Error{ | 5168 | , &[_]Error{ |
| 5169 | .expected_var_decl, | 5169 | .expected_var_decl, |
| ... | @@ -5173,12 +5173,12 @@ test "recovery: continue after invalid decl" { | ... | @@ -5173,12 +5173,12 @@ test "recovery: continue after invalid decl" { |
| 5173 | | 5173 | |
| 5174 | test "recovery: invalid extern/inline" { | 5174 | test "recovery: invalid extern/inline" { |
| 5175 | try testError( | 5175 | try testError( |
| 5176 | \\inline test "" { a && b; } | 5176 | \\inline test "" { a & b; } |
| 5177 | , &[_]Error{ | 5177 | , &[_]Error{ |
| 5178 | .expected_fn, | 5178 | .expected_fn, |
| 5179 | }); | 5179 | }); |
| 5180 | try testError( | 5180 | try testError( |
| 5181 | \\extern "" test "" { a && b; } | 5181 | \\extern "" test "" { a & b; } |
| 5182 | , &[_]Error{ | 5182 | , &[_]Error{ |
| 5183 | .expected_var_decl_or_fn, | 5183 | .expected_var_decl_or_fn, |
| 5184 | }); | 5184 | }); |
| ... | @@ -5187,8 +5187,8 @@ test "recovery: invalid extern/inline" { | ... | @@ -5187,8 +5187,8 @@ test "recovery: invalid extern/inline" { |
| 5187 | test "recovery: missing semicolon" { | 5187 | test "recovery: missing semicolon" { |
| 5188 | try testError( | 5188 | try testError( |
| 5189 | \\test "" { | 5189 | \\test "" { |
| 5190 | \\ comptime a && b | 5190 | \\ comptime a & b |
| 5191 | \\ c && d | 5191 | \\ c & d |
| 5192 | \\ @foo | 5192 | \\ @foo |
| 5193 | \\} | 5193 | \\} |
| 5194 | , &[_]Error{ | 5194 | , &[_]Error{ |
| ... | @@ -5206,7 +5206,7 @@ test "recovery: invalid container members" { | ... | @@ -5206,7 +5206,7 @@ test "recovery: invalid container members" { |
| 5206 | \\bar@, | 5206 | \\bar@, |
| 5207 | \\while (a == 2) { test "" {}} | 5207 | \\while (a == 2) { test "" {}} |
| 5208 | \\test "" { | 5208 | \\test "" { |
| 5209 | \\ a && b | 5209 | \\ a & b |
| 5210 | \\} | 5210 | \\} |
| 5211 | , &[_]Error{ | 5211 | , &[_]Error{ |
| 5212 | .expected_expr, | 5212 | .expected_expr, |
| ... | @@ -5224,7 +5224,7 @@ test "recovery: extra '}' at top level" { | ... | @@ -5224,7 +5224,7 @@ test "recovery: extra '}' at top level" { |
| 5224 | try testError( | 5224 | try testError( |
| 5225 | \\}}} | 5225 | \\}}} |
| 5226 | \\test "" { | 5226 | \\test "" { |
| 5227 | \\ a && b; | 5227 | \\ a & b; |
| 5228 | \\} | 5228 | \\} |
| 5229 | , &[_]Error{ | 5229 | , &[_]Error{ |
| 5230 | .expected_token, | 5230 | .expected_token, |
| ... | @@ -5244,7 +5244,7 @@ test "recovery: mismatched bracket at top level" { | ... | @@ -5244,7 +5244,7 @@ test "recovery: mismatched bracket at top level" { |
| 5244 | test "recovery: invalid global error set access" { | 5244 | test "recovery: invalid global error set access" { |
| 5245 | try testError( | 5245 | try testError( |
| 5246 | \\test "" { | 5246 | \\test "" { |
| 5247 | \\ error && foo; | 5247 | \\ error & foo; |
| 5248 | \\} | 5248 | \\} |
| 5249 | , &[_]Error{ | 5249 | , &[_]Error{ |
| 5250 | .expected_token, | 5250 | .expected_token, |
| ... | @@ -5259,13 +5259,15 @@ test "recovery: invalid asterisk after pointer dereference" { | ... | @@ -5259,13 +5259,15 @@ test "recovery: invalid asterisk after pointer dereference" { |
| 5259 | \\} | 5259 | \\} |
| 5260 | , &[_]Error{ | 5260 | , &[_]Error{ |
| 5261 | .asterisk_after_ptr_deref, | 5261 | .asterisk_after_ptr_deref, |
| | 5262 | .mismatched_binary_op_whitespace, |
| 5262 | }); | 5263 | }); |
| 5263 | try testError( | 5264 | try testError( |
| 5264 | \\test "" { | 5265 | \\test "" { |
| 5265 | \\ var sequence = "repeat".** 10&&a; | 5266 | \\ var sequence = "repeat".** 10&a; |
| 5266 | \\} | 5267 | \\} |
| 5267 | , &[_]Error{ | 5268 | , &[_]Error{ |
| 5268 | .asterisk_after_ptr_deref, | 5269 | .asterisk_after_ptr_deref, |
| | 5270 | .mismatched_binary_op_whitespace, |
| 5269 | }); | 5271 | }); |
| 5270 | } | 5272 | } |
| 5271 | | 5273 | |
| ... | @@ -5275,7 +5277,7 @@ test "recovery: missing semicolon after if, for, while stmt" { | ... | @@ -5275,7 +5277,7 @@ test "recovery: missing semicolon after if, for, while stmt" { |
| 5275 | \\ if (foo) bar | 5277 | \\ if (foo) bar |
| 5276 | \\ for (foo) |a| bar | 5278 | \\ for (foo) |a| bar |
| 5277 | \\ while (foo) bar | 5279 | \\ while (foo) bar |
| 5278 | \\ a && b; | 5280 | \\ a & b; |
| 5279 | \\} | 5281 | \\} |
| 5280 | , &[_]Error{ | 5282 | , &[_]Error{ |
| 5281 | .expected_semi_or_else, | 5283 | .expected_semi_or_else, |
| ... | @@ -5373,6 +5375,54 @@ test "recovery: eof in c pointer" { | ... | @@ -5373,6 +5375,54 @@ test "recovery: eof in c pointer" { |
| 5373 | }); | 5375 | }); |
| 5374 | } | 5376 | } |
| 5375 | | 5377 | |
| | 5378 | test "matching whitespace on minus op" { |
| | 5379 | try testError( |
| | 5380 | \\ _ = 2 -1, |
| | 5381 | \\ _ = 2- 1, |
| | 5382 | \\ _ = 2- |
| | 5383 | \\ 2, |
| | 5384 | \\ _ = 2 |
| | 5385 | \\ -2, |
| | 5386 | , &[_]Error{ |
| | 5387 | .mismatched_binary_op_whitespace, |
| | 5388 | .mismatched_binary_op_whitespace, |
| | 5389 | .mismatched_binary_op_whitespace, |
| | 5390 | .mismatched_binary_op_whitespace, |
| | 5391 | }); |
| | 5392 | |
| | 5393 | try testError( |
| | 5394 | \\ _ = - 1, |
| | 5395 | \\ _ = -1, |
| | 5396 | \\ _ = 2 - -1, |
| | 5397 | \\ _ = 2 - 1, |
| | 5398 | \\ _ = 2-1, |
| | 5399 | \\ _ = 2 - |
| | 5400 | \\1, |
| | 5401 | \\ _ = 2 |
| | 5402 | \\ - 1, |
| | 5403 | , &[_]Error{}); |
| | 5404 | } |
| | 5405 | |
| | 5406 | test "ampersand" { |
| | 5407 | try testError( |
| | 5408 | \\ _ = bar && foo, |
| | 5409 | \\ _ = bar&&foo, |
| | 5410 | \\ _ = bar& & foo, |
| | 5411 | \\ _ = bar& &foo, |
| | 5412 | , &.{ |
| | 5413 | .invalid_ampersand_ampersand, |
| | 5414 | .invalid_ampersand_ampersand, |
| | 5415 | .mismatched_binary_op_whitespace, |
| | 5416 | .mismatched_binary_op_whitespace, |
| | 5417 | }); |
| | 5418 | |
| | 5419 | try testError( |
| | 5420 | \\ _ = bar & &foo, |
| | 5421 | \\ _ = bar & &&foo, |
| | 5422 | \\ _ = &&foo, |
| | 5423 | , &.{}); |
| | 5424 | } |
| | 5425 | |
| 5376 | const std = @import("std"); | 5426 | const std = @import("std"); |
| 5377 | const mem = std.mem; | 5427 | const mem = std.mem; |
| 5378 | const print = std.debug.print; | 5428 | const print = std.debug.print; |
| ... | @@ -5466,7 +5516,10 @@ fn testError(source: [:0]const u8, expected_errors: []const Error) !void { | ... | @@ -5466,7 +5516,10 @@ fn testError(source: [:0]const u8, expected_errors: []const Error) !void { |
| 5466 | var tree = try std.zig.parse(std.testing.allocator, source); | 5516 | var tree = try std.zig.parse(std.testing.allocator, source); |
| 5467 | defer tree.deinit(std.testing.allocator); | 5517 | defer tree.deinit(std.testing.allocator); |
| 5468 | | 5518 | |
| 5469 | try std.testing.expectEqual(expected_errors.len, tree.errors.len); | 5519 | std.testing.expectEqual(expected_errors.len, tree.errors.len) catch |err| { |
| | 5520 | std.debug.print("errors found: {any}\n", .{tree.errors}); |
| | 5521 | return err; |
| | 5522 | }; |
| 5470 | for (expected_errors) |expected, i| { | 5523 | for (expected_errors) |expected, i| { |
| 5471 | try std.testing.expectEqual(expected, tree.errors[i].tag); | 5524 | try std.testing.expectEqual(expected, tree.errors[i].tag); |
| 5472 | } | 5525 | } |