zig/test/cases/syntax.zig

55 lines
1.1 KiB
Zig
Raw Normal View History

2017-06-15 20:54:23 -07:00
// Test trailing comma syntax
// zig fmt: off
2017-06-15 20:54:23 -07:00
const struct_trailing_comma = struct { x: i32, y: i32, };
const struct_no_comma = struct { x: i32, y: i32 };
const struct_fn_no_comma = struct { fn m() void {} y: i32 };
2017-06-15 20:54:23 -07:00
const enum_no_comma = enum { A, B };
fn container_init() void {
2017-06-15 20:54:23 -07:00
const S = struct { x: i32, y: i32 };
_ = S { .x = 1, .y = 2 };
_ = S { .x = 1, .y = 2, };
}
fn switch_cases(x: i32) void {
2017-06-15 20:54:23 -07:00
switch (x) {
1,2,3 => {},
4,5, => {},
6...8, => {},
else => {},
}
}
fn switch_prongs(x: i32) void {
2017-06-15 20:54:23 -07:00
switch (x) {
0 => {},
else => {},
}
switch (x) {
0 => {},
else => {}
}
}
const fn_no_comma = fn(i32, i32)void;
const fn_trailing_comma = fn(i32, i32,)void;
2017-06-15 20:54:23 -07:00
fn fn_calls() void {
fn add(x: i32, y: i32,) i32 { x + y };
2017-06-15 20:54:23 -07:00
_ = add(1, 2);
_ = add(1, 2,);
}
fn asm_lists() void {
2017-06-15 20:54:23 -07:00
if (false) { // Build AST but don't analyze
asm ("not real assembly"
:[a] "x" (x),);
asm ("not real assembly"
:[a] "x" (->i32),:[a] "x" (1),);
asm ("still not real assembly"
:::"a","b",);
}
}