Skip to content

Commit

Permalink
Gets all ZON tests passing locally
Browse files Browse the repository at this point in the history
  • Loading branch information
MasonRemaley committed Dec 3, 2024
1 parent e7cc148 commit 0f41cf8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
18 changes: 14 additions & 4 deletions lib/std/zig/string_literal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -392,18 +392,22 @@ pub fn MultilineParser(comptime Writer: type) type {
};
}

/// Parse one line of a multiline string, writing the result to the writer prepending a newline if necessary.
/// Parse one line of a multiline string, writing the result to the writer prepending a
/// newline if necessary.
///
/// Asserts bytes begins with "\\". The line may be terminated with '\n' or "\r\n", but may not contain any interior newlines.
/// contain any interior newlines.
/// Asserts bytes begins with "\\". The line may be terminated with '\n' or "\r\n", but may
/// not contain any interior newlines.
pub fn line(self: *@This(), bytes: []const u8) Writer.Error!void {
assert(bytes.len >= 2 and bytes[0] == '\\' and bytes[1] == '\\');
var terminator_len: usize = 0;
terminator_len += @intFromBool(bytes[bytes.len - 1] == '\n');
terminator_len += @intFromBool(bytes[bytes.len - 2] == '\r');
if (self.first_line) {
self.first_line = false;
} else {
try self.writer.writeByte('\n');
}
try self.writer.writeAll(bytes[2..]);
try self.writer.writeAll(bytes[2 .. bytes.len - terminator_len]);
}
};
}
Expand All @@ -427,12 +431,18 @@ test "parse multiline" {
}

{
const temp =
\\foo
\\bar
;
try std.testing.expectEqualStrings("foo\nbar", temp);
var parsed = std.ArrayList(u8).init(std.testing.allocator);
defer parsed.deinit();
const writer = parsed.writer();
var parser = multilineParser(writer);
try parser.line("\\\\foo");
try std.testing.expectEqualStrings("foo", parsed.items);
// XXX: this adds the newline but like...does the input ever actually have a newline there?
try parser.line("\\\\bar\n");
try std.testing.expectEqualStrings("foo\nbar", parsed.items);
}
Expand Down
1 change: 1 addition & 0 deletions test/cases/compile_errors/@import_zon_negative_zero.zig
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ pub fn main() void {
// imports=zon/negative_zero.zon
//
// negative_zero.zon:1:1: error: integer literal '-0' is ambiguous
// tmp.zig:2:27: note: imported here
11 changes: 0 additions & 11 deletions test/cases/compile_errors/@import_zon_negative_zero_cast_float.zig

This file was deleted.

0 comments on commit 0f41cf8

Please sign in to comment.