|
| 1 | +// source: https://ziglang.org/documentation/master/#String-Literals-and-Character-Literals |
| 2 | + |
| 3 | +const expect = @import("std").testing.expect; |
| 4 | +const mem = @import("std").mem; |
| 5 | + |
| 6 | +test "string literals" { |
| 7 | + const bytes = "hello"; |
| 8 | + expect(@TypeOf(bytes) == *const [5:0]u8); |
| 9 | + expect(bytes.len == 5); |
| 10 | + expect(bytes[1] == 'e'); |
| 11 | + expect(bytes[5] == 0); |
| 12 | + expect('e' == '\x65'); |
| 13 | + expect('\u{1f4a9}' == 128169); |
| 14 | + expect('💯' == 128175); |
| 15 | + expect(mem.eql(u8, "hello", "h\x65llo")); |
| 16 | +} |
| 17 | + |
| 18 | +const hello_world_in_c = |
| 19 | + \\#include <stdio.h> |
| 20 | + \\ |
| 21 | + \\int main(int argc, char **argv) { |
| 22 | + \\ printf("hello world\n"); |
| 23 | + \\ return 0; |
| 24 | + \\} |
| 25 | +; |
| 26 | + |
| 27 | +---------------------------------------------------- |
| 28 | + |
| 29 | +[ |
| 30 | + ["comment", "// source: https://ziglang.org/documentation/master/#String-Literals-and-Character-Literals"], |
| 31 | + |
| 32 | + ["keyword", "const"], |
| 33 | + " expect ", |
| 34 | + ["operator", "="], |
| 35 | + ["builtin", "@import"], |
| 36 | + ["punctuation", "("], |
| 37 | + ["string", "\"std\""], |
| 38 | + ["punctuation", ")"], |
| 39 | + ["punctuation", "."], |
| 40 | + "testing", |
| 41 | + ["punctuation", "."], |
| 42 | + "expect", |
| 43 | + ["punctuation", ";"], |
| 44 | + |
| 45 | + ["keyword", "const"], |
| 46 | + " mem ", |
| 47 | + ["operator", "="], |
| 48 | + ["builtin", "@import"], |
| 49 | + ["punctuation", "("], |
| 50 | + ["string", "\"std\""], |
| 51 | + ["punctuation", ")"], |
| 52 | + ["punctuation", "."], |
| 53 | + "mem", |
| 54 | + ["punctuation", ";"], |
| 55 | + |
| 56 | + ["keyword", "test"], |
| 57 | + ["string", "\"string literals\""], |
| 58 | + ["punctuation", "{"], |
| 59 | + |
| 60 | + ["keyword", "const"], |
| 61 | + " bytes ", |
| 62 | + ["operator", "="], |
| 63 | + ["string", "\"hello\""], |
| 64 | + ["punctuation", ";"], |
| 65 | + |
| 66 | + ["function", "expect"], |
| 67 | + ["punctuation", "("], |
| 68 | + ["builtin", "@TypeOf"], |
| 69 | + ["punctuation", "("], |
| 70 | + "bytes", |
| 71 | + ["punctuation", ")"], |
| 72 | + ["operator", "=="], |
| 73 | + ["operator", "*"], |
| 74 | + ["keyword", "const"], |
| 75 | + ["punctuation", "["], |
| 76 | + ["number", "5"], |
| 77 | + ["punctuation", ":"], |
| 78 | + ["number", "0"], |
| 79 | + ["punctuation", "]"], |
| 80 | + ["builtin-types", "u8"], |
| 81 | + ["punctuation", ")"], |
| 82 | + ["punctuation", ";"], |
| 83 | + |
| 84 | + ["function", "expect"], |
| 85 | + ["punctuation", "("], |
| 86 | + "bytes", |
| 87 | + ["punctuation", "."], |
| 88 | + "len ", |
| 89 | + ["operator", "=="], |
| 90 | + ["number", "5"], |
| 91 | + ["punctuation", ")"], |
| 92 | + ["punctuation", ";"], |
| 93 | + |
| 94 | + ["function", "expect"], |
| 95 | + ["punctuation", "("], |
| 96 | + "bytes", |
| 97 | + ["punctuation", "["], |
| 98 | + ["number", "1"], |
| 99 | + ["punctuation", "]"], |
| 100 | + ["operator", "=="], |
| 101 | + ["string", "'e'"], |
| 102 | + ["punctuation", ")"], |
| 103 | + ["punctuation", ";"], |
| 104 | + |
| 105 | + ["function", "expect"], |
| 106 | + ["punctuation", "("], |
| 107 | + "bytes", |
| 108 | + ["punctuation", "["], |
| 109 | + ["number", "5"], |
| 110 | + ["punctuation", "]"], |
| 111 | + ["operator", "=="], |
| 112 | + ["number", "0"], |
| 113 | + ["punctuation", ")"], |
| 114 | + ["punctuation", ";"], |
| 115 | + |
| 116 | + ["function", "expect"], |
| 117 | + ["punctuation", "("], |
| 118 | + ["string", "'e'"], |
| 119 | + ["operator", "=="], |
| 120 | + ["string", "'\\x65'"], |
| 121 | + ["punctuation", ")"], |
| 122 | + ["punctuation", ";"], |
| 123 | + |
| 124 | + ["function", "expect"], |
| 125 | + ["punctuation", "("], |
| 126 | + ["string", "'\\u{1f4a9}'"], |
| 127 | + ["operator", "=="], |
| 128 | + ["number", "128169"], |
| 129 | + ["punctuation", ")"], |
| 130 | + ["punctuation", ";"], |
| 131 | + |
| 132 | + ["function", "expect"], |
| 133 | + ["punctuation", "("], |
| 134 | + ["string", "'💯'"], |
| 135 | + ["operator", "=="], |
| 136 | + ["number", "128175"], |
| 137 | + ["punctuation", ")"], |
| 138 | + ["punctuation", ";"], |
| 139 | + |
| 140 | + ["function", "expect"], |
| 141 | + ["punctuation", "("], |
| 142 | + "mem", |
| 143 | + ["punctuation", "."], |
| 144 | + ["function", "eql"], |
| 145 | + ["punctuation", "("], |
| 146 | + ["builtin-types", "u8"], |
| 147 | + ["punctuation", ","], |
| 148 | + ["string", "\"hello\""], |
| 149 | + ["punctuation", ","], |
| 150 | + ["string", "\"h\\x65llo\""], |
| 151 | + ["punctuation", ")"], |
| 152 | + ["punctuation", ")"], |
| 153 | + ["punctuation", ";"], |
| 154 | + |
| 155 | + ["punctuation", "}"], |
| 156 | + |
| 157 | + ["keyword", "const"], " hello_world_in_c ", ["operator", "="], |
| 158 | + ["string", " \\\\#include <stdio.h>\r\n \\\\\r\n \\\\int main(int argc, char **argv) {\r\n \\\\ printf(\"hello world\\n\");\r\n \\\\ return 0;\r\n \\\\}"], |
| 159 | + ["punctuation", ";"] |
| 160 | +] |
0 commit comments