on master help sign in
Update Zig syntax test output
commitb3f34529b5122743f13642c8c4a63008719c2b6f authorsharkdp <davidpeter@web.de> dateSat 2 Jan 2021, 21:17 (6 years ago) parentd388d07
1 file changed+97−97
tests/syntax-tests/highlighted/Zig/example.zig+97−97
tests/syntax-tests/highlighted/Zig/example.zig+97−97
@@ -1,107 +1,107 @@
1−//! this is a top level doc, starts with "//!"
1+//! this is a top level doc, starts with "//!"
22
3−const std = @import("std");
3+const std = @import("std");
44
5−pub fn main() anyerror!void {
6− const stdout = std.io.getStdOut().writer();
7− try stdout.print("Hello, {}!\n", .{"world"});
5+pub fn main() anyerror!void {
6+ const stdout = std.io.getStdOut().writer();
7+ try stdout.print("Hello, {}!\n", .{"world"});
88}
99
10−const expect = std.testing.expect;
10+const expect = std.testing.expect;
1111
12−test "comments" {
13− // comments start with "//" until newline
14− // foo bar baz
15− const x = true; // another comment
16− expect(x);
12+test "comments" {
13+ // comments start with "//" until newline
14+ // foo bar baz
15+ const x = true; // another comment
16+ expect(x);
1717}
1818
19−/// a doc comment starts with "///"
20−/// multiple lines are merged together
21−const Timestamp = struct {
22− /// number of seconds since epoch
23− seconds: i64,
24−
25− /// number of nanoseconds past the second
26− nano: u32,
27−
28− const Self = @This();
29−
30− pub fn unixEpoch() Self {
31− return Self{
32− .seconds = 0,
33− .nanos = 0,
34− };
35− }
36−};
37−
38−const my_val = switch (std.Target.current.os.tag) {
39− .linux => "Linux",
40− else => "not Linux",
41−};
42−
43−const Book = enum {
44− paperback,
45− hardcover,
46− ebook,
47− pdf,
48−};
49−
50−const TokenType = union(enum) {
51− int: isize,
52− float: f64,
53− string: []const u8,
54−};
55−
56−const array_lit: [4]u8 = .{ 11, 22, 33, 44 };
57−const sentinal_lit = [_:0]u8{ 1, 2, 3, 4 };
58−
59−test "address of syntax" {
60− // Get the address of a variable:
61− const x: i32 = 1234;
62− const x_ptr = &x;
63−
64− // Dereference a pointer:
65− expect(x_ptr.* == 1234);
66−
67− // When you get the address of a const variable, you get a const pointer to a single item.
68− expect(@TypeOf(x_ptr) == *const i32);
69−
70− // If you want to mutate the value, you'd need an address of a mutable variable:
71− var y: i32 = 5678;
72− const y_ptr = &y;
73− expect(@TypeOf(y_ptr) == *i32);
74− y_ptr.* += 1;
75− expect(y_ptr.* == 5679);
19+/// a doc comment starts with "///"
20+/// multiple lines are merged together
21+const Timestamp = struct {
22+ /// number of seconds since epoch
23+ seconds: i64,
24+
25+ /// number of nanoseconds past the second
26+ nano: u32,
27+
28+ const Self = @This();
29+
30+ pub fn unixEpoch() Self {
31+ return Self{
32+ .seconds = 0,
33+ .nanos = 0,
34+ };
35+ }
36+};
37+
38+const my_val = switch (std.Target.current.os.tag) {
39+ .linux => "Linux",
40+ else => "not Linux",
41+};
42+
43+const Book = enum {
44+ paperback,
45+ hardcover,
46+ ebook,
47+ pdf,
48+};
49+
50+const TokenType = union(enum) {
51+ int: isize,
52+ float: f64,
53+ string: []const u8,
54+};
55+
56+const array_lit: [4]u8 = .{ 11, 22, 33, 44 };
57+const sentinal_lit = [_:0]u8{ 1, 2, 3, 4 };
58+
59+test "address of syntax" {
60+ // Get the address of a variable:
61+ const x: i32 = 1234;
62+ const x_ptr = &x;
63+
64+ // Dereference a pointer:
65+ expect(x_ptr.* == 1234);
66+
67+ // When you get the address of a const variable, you get a const pointer to a single item.
68+ expect(@TypeOf(x_ptr) == *const i32);
69+
70+ // If you want to mutate the value, you'd need an address of a mutable variable:
71+ var y: i32 = 5678;
72+ const y_ptr = &y;
73+ expect(@TypeOf(y_ptr) == *i32);
74+ y_ptr.* += 1;
75+ expect(y_ptr.* == 5679);
7676}
7777
78−// integer literals
79−const decimal_int = 98222;
80−const hex_int = 0xff;
81−const another_hex_int = 0xFF;
82−const octal_int = 0o755;
83−const binary_int = 0b11110000;
84−
85−// underscores may be placed between two digits as a visual separator
86−const one_billion = 1_000_000_000;
87−const binary_mask = 0b1_1111_1111;
88−const permissions = 0o7_5_5;
89−const big_address = 0xFF80_0000_0000_0000;
90−
91−// float literals
92−const floating_point = 123.0E+77;
93−const another_float = 123.0;
94−const yet_another = 123.0e+77;
95−
96−const hex_floating_point = 0x103.70p-5;
97−const another_hex_float = 0x103.70;
98−const yet_another_hex_float = 0x103.70P-5;
99−
100−// underscores may be placed between two digits as a visual separator
101−const lightspeed = 299_792_458.000_000;
102−const nanosecond = 0.000_000_001;
103−const more_hex = 0x1234_5678.9ABC_CDEFp-10;
104−
105−fn max(comptime T: type, a: T, b: T) T {
106− return if (a > b) a else b;
78+// integer literals
79+const decimal_int = 98222;
80+const hex_int = 0xff;
81+const another_hex_int = 0xFF;
82+const octal_int = 0o755;
83+const binary_int = 0b11110000;
84+
85+// underscores may be placed between two digits as a visual separator
86+const one_billion = 1_000_000_000;
87+const binary_mask = 0b1_1111_1111;
88+const permissions = 0o7_5_5;
89+const big_address = 0xFF80_0000_0000_0000;
90+
91+// float literals
92+const floating_point = 123.0E+77;
93+const another_float = 123.0;
94+const yet_another = 123.0e+77;
95+
96+const hex_floating_point = 0x103.70p-5;
97+const another_hex_float = 0x103.70;
98+const yet_another_hex_float = 0x103.70P-5;
99+
100+// underscores may be placed between two digits as a visual separator
101+const lightspeed = 299_792_458.000_000;
102+const nanosecond = 0.000_000_001;
103+const more_hex = 0x1234_5678.9ABC_CDEFp-10;
104+
105+fn max(comptime T: type, a: T, b: T) T {
106+ return if (a > b) a else b;
107107}