aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEvan Haas <evan@lagerdata.com>2021-01-17 19:22:48 -0800
committerAndrew Kelley <andrew@ziglang.org>2021-01-18 11:05:51 -0800
commitc3dadfa95b01d140460eb3d3d47d13859302f298 (patch)
tree8d0135b3319b548b44e7f6ab1c9ba73d45a16788 /test
parent384ccaa27a979f406f41e1617d3c9ef015517fda (diff)
downloadzig-c3dadfa95b01d140460eb3d3d47d13859302f298.tar.gz
zig-c3dadfa95b01d140460eb3d3d47d13859302f298.zip
translate-c: Add Wide, UTF-16, and UTF-32 character literals
Add support for L'<wchar_t>', u'<char16_t>', and U'<char32_t>'. Currently this just translates wide char literals to \u{NNNNNN} escape codes (e.g. U'💯' -> '\u{1f4af}') Another approach would be to emit UTF-8 encoded character literals directly, but in my opinion this approaches Unicode-complete because it would require knowledge of which Unicode codepoints have graphical representations for the emitted source to be readable. We could also just emit integer literals, but the current method makes it clear that we have translated a wide character literal and not just an integer constant.
Diffstat (limited to 'test')
-rw-r--r--test/run_translated_c.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/run_translated_c.zig b/test/run_translated_c.zig
index f719d0fe40..1395274251 100644
--- a/test/run_translated_c.zig
+++ b/test/run_translated_c.zig
@@ -719,4 +719,22 @@ pub fn addCases(cases: *tests.RunTranslatedCContext) void {
\\ return 0;
\\}
, "");
+
+ cases.add("Wide, UTF-16, and UTF-32 character literals",
+ \\#include <wchar.h>
+ \\#include <stdlib.h>
+ \\int main() {
+ \\ wchar_t wc = L'â„¢';
+ \\ int utf16_char = u'â„¢';
+ \\ int utf32_char = U'💯';
+ \\ if (wc != 8482) abort();
+ \\ if (utf16_char != 8482) abort();
+ \\ if (utf32_char != 128175) abort();
+ \\ unsigned char c = wc;
+ \\ if (c != 0x22) abort();
+ \\ c = utf32_char;
+ \\ if (c != 0xaf) abort();
+ \\ return 0;
+ \\}
+ , "");
}