zig/test/cases3/misc.zig

129 lines
2.6 KiB
Zig

// normal comment
/// this is a documentation comment
/// doc comment line 2
fn emptyFunctionWithComments() {
@setFnTest(this);
}
export fn disabledExternFn() {
@setFnVisible(this, false);
}
fn callDisabledExternFn() {
@setFnTest(this);
disabledExternFn();
}
fn intTypeBuiltin() {
@setFnTest(this);
assert(@intType(true, 8) == i8);
assert(@intType(true, 16) == i16);
assert(@intType(true, 32) == i32);
assert(@intType(true, 64) == i64);
assert(@intType(false, 8) == u8);
assert(@intType(false, 16) == u16);
assert(@intType(false, 32) == u32);
assert(@intType(false, 64) == u64);
assert(i8.bit_count == 8);
assert(i16.bit_count == 16);
assert(i32.bit_count == 32);
assert(i64.bit_count == 64);
assert(i8.is_signed);
assert(i16.is_signed);
assert(i32.is_signed);
assert(i64.is_signed);
assert(isize.is_signed);
assert(!u8.is_signed);
assert(!u16.is_signed);
assert(!u32.is_signed);
assert(!u64.is_signed);
assert(!usize.is_signed);
}
fn minValueAndMaxValue() {
@setFnTest(this);
assert(@maxValue(u8) == 255);
assert(@maxValue(u16) == 65535);
assert(@maxValue(u32) == 4294967295);
assert(@maxValue(u64) == 18446744073709551615);
assert(@maxValue(i8) == 127);
assert(@maxValue(i16) == 32767);
assert(@maxValue(i32) == 2147483647);
assert(@maxValue(i64) == 9223372036854775807);
assert(@minValue(u8) == 0);
assert(@minValue(u16) == 0);
assert(@minValue(u32) == 0);
assert(@minValue(u64) == 0);
assert(@minValue(i8) == -128);
assert(@minValue(i16) == -32768);
assert(@minValue(i32) == -2147483648);
assert(@minValue(i64) == -9223372036854775808);
}
fn shortCircuit() {
@setFnTest(this);
var hit_1 = false;
var hit_2 = false;
var hit_3 = false;
var hit_4 = false;
if (true || {assert(false); false}) {
hit_1 = true;
}
if (false || { hit_2 = true; false }) {
assert(false);
}
if (true && { hit_3 = true; false }) {
assert(false);
}
if (false && {assert(false); false}) {
assert(false);
} else {
hit_4 = true;
}
assert(hit_1);
assert(hit_2);
assert(hit_3);
assert(hit_4);
}
fn truncate() {
@setFnTest(this);
assert(testTruncate(0x10fd) == 0xfd);
}
fn testTruncate(x: u32) -> u8 {
@truncate(u8, x)
}
fn assignToIfVarPtr() {
@setFnTest(this);
var maybe_bool: ?bool = true;
if (const *b ?= maybe_bool) {
*b = false;
}
assert(??maybe_bool == false);
}
// TODO const assert = @import("std").debug.assert;
fn assert(ok: bool) {
if (!ok)
@unreachable();
}