| ... | @@ -1721,10 +1721,14 @@ fn testTokenize(source: [:0]const u8, expected_token_tags: []const Token.Tag) !v | ... | @@ -1721,10 +1721,14 @@ fn testTokenize(source: [:0]const u8, expected_token_tags: []const Token.Tag) !v |
| 1721 | try std.testing.expectEqual(source.len, last_token.loc.end); | 1721 | try std.testing.expectEqual(source.len, last_token.loc.end); |
| 1722 | } | 1722 | } |
| 1723 | | 1723 | |
| 1724 | fn testPropertiesUpheld(context: void, source: []const u8) anyerror!void { | 1724 | fn testPropertiesUpheld(_: void, source: []const u8) !void { |
| 1725 | _ = context; | 1725 | var source0_buf: [512]u8 = undefined; |
| 1726 | const source0 = try std.testing.allocator.dupeZ(u8, source); | 1726 | if (source.len + 1 > source0_buf.len) |
| 1727 | defer std.testing.allocator.free(source0); | 1727 | return; |
| | 1728 | @memcpy(source0_buf[0..source.len], source); |
| | 1729 | source0_buf[source.len] = 0; |
| | 1730 | const source0 = source0_buf[0..source.len :0]; |
| | 1731 | |
| 1728 | var tokenizer = Tokenizer.init(source0); | 1732 | var tokenizer = Tokenizer.init(source0); |
| 1729 | var tokenization_failed = false; | 1733 | var tokenization_failed = false; |
| 1730 | while (true) { | 1734 | while (true) { |
| ... | @@ -1750,18 +1754,15 @@ fn testPropertiesUpheld(context: void, source: []const u8) anyerror!void { | ... | @@ -1750,18 +1754,15 @@ fn testPropertiesUpheld(context: void, source: []const u8) anyerror!void { |
| 1750 | } | 1754 | } |
| 1751 | } | 1755 | } |
| 1752 | | 1756 | |
| 1753 | if (source0.len > 0) for (source0, source0[1..][0..source0.len]) |cur, next| { | 1757 | if (tokenization_failed) return; |
| | 1758 | for (source0) |cur| { |
| 1754 | // Property: No null byte allowed except at end. | 1759 | // Property: No null byte allowed except at end. |
| 1755 | if (cur == 0) { | 1760 | if (cur == 0) { |
| 1756 | try std.testing.expect(tokenization_failed); | 1761 | return error.TestUnexpectedResult; |
| 1757 | } | | |
| 1758 | // Property: No ASCII control characters other than \n and \t are allowed. | | |
| 1759 | if (std.ascii.isControl(cur) and cur != '\n' and cur != '\t') { | | |
| 1760 | try std.testing.expect(tokenization_failed); | | |
| 1761 | } | 1762 | } |
| 1762 | // Property: All '\r' must be followed by '\n'. | 1763 | // Property: No ASCII control characters other than \n, \t, and \r are allowed. |
| 1763 | if (cur == '\r' and next != '\n') { | 1764 | if (std.ascii.isControl(cur) and cur != '\n' and cur != '\t' and cur != '\r') { |
| 1764 | try std.testing.expect(tokenization_failed); | 1765 | return error.TestUnexpectedResult; |
| 1765 | } | 1766 | } |
| 1766 | }; | 1767 | } |
| 1767 | } | 1768 | } |