Commit e283a40d17
Changed files (3)
test
src/translate_c.zig
@@ -5799,7 +5799,7 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {
}
}
for (source) |c| {
- if (c == '\\') {
+ if (c == '\\' or c == '\t') {
break;
}
} else return source;
@@ -5876,6 +5876,13 @@ fn zigifyEscapeSequences(ctx: *Context, m: *MacroCtx) ![]const u8 {
state = .Start;
},
.Start => {
+ if (c == '\t') {
+ bytes[i] = '\\';
+ i += 1;
+ bytes[i] = 't';
+ i += 1;
+ continue;
+ }
if (c == '\\') {
state = .Escape;
}
test/behavior/translate_c_macros.h
@@ -50,3 +50,5 @@ typedef _Bool uintptr_t;
#define CAST_TO_UINTPTR(X) (uintptr_t)(X)
#define LARGE_INT 18446744073709550592
+
+#define EMBEDDED_TAB "hello "
test/behavior/translate_c_macros.zig
@@ -2,6 +2,7 @@ const builtin = @import("builtin");
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
+const expectEqualStrings = std.testing.expectEqualStrings;
const h = @cImport(@cInclude("behavior/translate_c_macros.h"));
@@ -123,3 +124,13 @@ test "large integer macro" {
try expectEqual(@as(c_ulonglong, 18446744073709550592), h.LARGE_INT);
}
+
+test "string literal macro with embedded tab character" {
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+
+ try expectEqualStrings("hello\t", h.EMBEDDED_TAB);
+}