2016-02-27 21:06:46 -08:00
|
|
|
// test std library
|
2016-04-08 13:13:33 -07:00
|
|
|
use @import("std");
|
2016-02-09 08:51:25 -08:00
|
|
|
|
2016-02-03 20:34:09 -08:00
|
|
|
#attribute("test")
|
|
|
|
fn empty_function() {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* multi line doc comment
|
|
|
|
*/
|
|
|
|
/// this is a documentation comment
|
|
|
|
/// doc comment line 2
|
|
|
|
#attribute("test")
|
|
|
|
fn comments() {
|
|
|
|
comments_f1(/* mid-line comment /* nested */ */ "OK\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn comments_f1(s: []u8) {}
|
|
|
|
|
|
|
|
|
2016-02-09 17:50:53 -08:00
|
|
|
#attribute("test")
|
|
|
|
fn if_statements() {
|
|
|
|
should_be_equal(1, 1);
|
|
|
|
first_eql_third(2, 1, 2);
|
|
|
|
}
|
|
|
|
fn should_be_equal(a: i32, b: i32) {
|
|
|
|
if (a != b) {
|
|
|
|
unreachable{};
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn first_eql_third(a: i32, b: i32, c: i32) {
|
|
|
|
if (a == b) {
|
|
|
|
unreachable{};
|
|
|
|
} else if (b == c) {
|
|
|
|
unreachable{};
|
|
|
|
} else if (a == c) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
unreachable{};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn local_variables() {
|
|
|
|
test_loc_vars(2);
|
|
|
|
}
|
|
|
|
fn test_loc_vars(b: i32) {
|
|
|
|
const a: i32 = 1;
|
|
|
|
if (a + b != 3) unreachable{};
|
|
|
|
}
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn bool_literals() {
|
2016-04-09 14:21:00 -07:00
|
|
|
assert(true);
|
|
|
|
assert(!false);
|
2016-02-09 17:50:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn separate_block_scopes() {
|
|
|
|
{
|
|
|
|
const no_conflict : i32 = 5;
|
|
|
|
assert(no_conflict == 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
const c = {
|
|
|
|
const no_conflict = i32(10);
|
|
|
|
no_conflict
|
|
|
|
};
|
|
|
|
assert(c == 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn void_struct_fields() {
|
|
|
|
const foo = VoidStructFieldsFoo {
|
|
|
|
.a = void{},
|
|
|
|
.b = 1,
|
|
|
|
.c = void{},
|
|
|
|
};
|
|
|
|
assert(foo.b == 1);
|
|
|
|
assert(@sizeof(VoidStructFieldsFoo) == 4);
|
|
|
|
}
|
|
|
|
struct VoidStructFieldsFoo {
|
|
|
|
a : void,
|
|
|
|
b : i32,
|
|
|
|
c : void,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn void_arrays() {
|
|
|
|
var array: [4]void = undefined;
|
|
|
|
array[0] = void{};
|
|
|
|
array[1] = array[2];
|
|
|
|
assert(@sizeof(@typeof(array)) == 0);
|
|
|
|
assert(array.len == 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn three_expr_in_a_row() {
|
|
|
|
assert_false(false || false || false);
|
|
|
|
assert_false(true && true && false);
|
|
|
|
assert_false(1 | 2 | 4 != 7);
|
|
|
|
assert_false(3 ^ 6 ^ 8 != 13);
|
|
|
|
assert_false(7 & 14 & 28 != 4);
|
|
|
|
assert_false(9 << 1 << 2 != 9 << 3);
|
|
|
|
assert_false(90 >> 1 >> 2 != 90 >> 3);
|
|
|
|
assert_false(100 - 1 + 1000 != 1099);
|
|
|
|
assert_false(5 * 4 / 2 % 3 != 1);
|
|
|
|
assert_false(i32(i32(5)) != 5);
|
|
|
|
assert_false(!!false);
|
|
|
|
assert_false(i32(7) != --(i32(7)));
|
|
|
|
}
|
|
|
|
fn assert_false(b: bool) {
|
|
|
|
assert(!b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn maybe_type() {
|
|
|
|
const x : ?bool = true;
|
|
|
|
|
|
|
|
if (const y ?= x) {
|
|
|
|
if (y) {
|
|
|
|
// OK
|
|
|
|
} else {
|
|
|
|
unreachable{};
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unreachable{};
|
|
|
|
}
|
|
|
|
|
|
|
|
const next_x : ?i32 = null;
|
|
|
|
|
|
|
|
const z = next_x ?? 1234;
|
|
|
|
|
|
|
|
assert(z == 1234);
|
|
|
|
|
|
|
|
const final_x : ?i32 = 13;
|
|
|
|
|
|
|
|
const num = final_x ?? unreachable{};
|
|
|
|
|
|
|
|
assert(num == 13);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn enum_type() {
|
|
|
|
const foo1 = EnumTypeFoo.One(13);
|
|
|
|
const foo2 = EnumTypeFoo.Two(EnumType { .x = 1234, .y = 5678, });
|
|
|
|
const bar = EnumTypeBar.B;
|
|
|
|
|
|
|
|
assert(bar == EnumTypeBar.B);
|
|
|
|
assert(@member_count(EnumTypeFoo) == 3);
|
|
|
|
assert(@member_count(EnumTypeBar) == 4);
|
2016-02-12 01:04:46 -08:00
|
|
|
const expected_foo_size = switch (@compile_var("arch")) {
|
|
|
|
i386 => 20,
|
|
|
|
x86_64 => 24,
|
|
|
|
else => unreachable{},
|
|
|
|
};
|
|
|
|
assert(@sizeof(EnumTypeFoo) == expected_foo_size);
|
2016-02-09 17:50:53 -08:00
|
|
|
assert(@sizeof(EnumTypeBar) == 1);
|
|
|
|
}
|
|
|
|
struct EnumType {
|
|
|
|
x: u64,
|
|
|
|
y: u64,
|
|
|
|
}
|
|
|
|
enum EnumTypeFoo {
|
|
|
|
One: i32,
|
|
|
|
Two: EnumType,
|
|
|
|
Three: void,
|
|
|
|
}
|
|
|
|
enum EnumTypeBar {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C,
|
|
|
|
D,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn array_literal() {
|
|
|
|
const HEX_MULT = []u16{4096, 256, 16, 1};
|
|
|
|
|
|
|
|
assert(HEX_MULT.len == 4);
|
|
|
|
assert(HEX_MULT[1] == 256);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn const_number_literal() {
|
|
|
|
const one = 1;
|
|
|
|
const eleven = ten + one;
|
|
|
|
|
|
|
|
assert(eleven == 11);
|
|
|
|
}
|
|
|
|
const ten = 10;
|
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn error_values() {
|
|
|
|
const a = i32(error.err1);
|
|
|
|
const b = i32(error.err2);
|
|
|
|
assert(a != b);
|
|
|
|
}
|
|
|
|
error err1;
|
|
|
|
error err2;
|
|
|
|
|
2016-02-03 20:34:09 -08:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn fn_call_of_struct_field() {
|
|
|
|
if (call_struct_field(Foo {.ptr = a_func,}) != 13) {
|
|
|
|
unreachable{};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Foo {
|
|
|
|
ptr: fn() -> i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn a_func() -> i32 { 13 }
|
|
|
|
|
|
|
|
fn call_struct_field(foo: Foo) -> i32 {
|
|
|
|
return foo.ptr();
|
|
|
|
}
|
2016-02-03 23:58:45 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-04 01:11:50 -08:00
|
|
|
#attribute("test")
|
|
|
|
fn redefinition_of_error_values_allowed() {
|
2016-02-09 17:50:53 -08:00
|
|
|
should_be_not_equal(error.AnError, error.SecondError);
|
2016-02-04 01:11:50 -08:00
|
|
|
}
|
2016-02-03 23:58:45 -08:00
|
|
|
error AnError;
|
|
|
|
error AnError;
|
|
|
|
error SecondError;
|
2016-02-09 17:50:53 -08:00
|
|
|
fn should_be_not_equal(a: error, b: error) {
|
|
|
|
if (a == b) unreachable{}
|
|
|
|
}
|
2016-02-03 23:58:45 -08:00
|
|
|
|
2016-02-04 01:11:50 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-02-03 23:58:45 -08:00
|
|
|
#attribute("test")
|
2016-02-04 01:11:50 -08:00
|
|
|
fn constant_enum_with_payload() {
|
2016-02-04 14:26:27 -08:00
|
|
|
var empty = AnEnumWithPayload.Empty;
|
|
|
|
var full = AnEnumWithPayload.Full(13);
|
|
|
|
should_be_empty(empty);
|
|
|
|
should_be_not_empty(full);
|
2016-02-04 01:11:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn should_be_empty(x: AnEnumWithPayload) {
|
2016-02-04 14:26:27 -08:00
|
|
|
switch (x) {
|
2016-02-04 15:09:06 -08:00
|
|
|
Empty => {},
|
2016-02-04 14:26:27 -08:00
|
|
|
else => unreachable{},
|
|
|
|
}
|
2016-02-04 01:11:50 -08:00
|
|
|
}
|
|
|
|
|
2016-02-04 01:49:12 -08:00
|
|
|
fn should_be_not_empty(x: AnEnumWithPayload) {
|
2016-02-04 14:26:27 -08:00
|
|
|
switch (x) {
|
2016-02-04 15:09:06 -08:00
|
|
|
Empty => unreachable{},
|
2016-02-04 14:26:27 -08:00
|
|
|
else => {},
|
|
|
|
}
|
2016-02-04 01:11:50 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
enum AnEnumWithPayload {
|
|
|
|
Empty,
|
|
|
|
Full: i32,
|
2016-02-03 23:58:45 -08:00
|
|
|
}
|
2016-02-04 01:49:12 -08:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn continue_in_for_loop() {
|
|
|
|
const array = []i32 {1, 2, 3, 4, 5};
|
|
|
|
var sum : i32 = 0;
|
2016-02-05 16:15:19 -08:00
|
|
|
for (array) |x| {
|
2016-02-04 01:49:12 -08:00
|
|
|
sum += x;
|
|
|
|
if (x < 3) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (sum != 6) unreachable{}
|
|
|
|
}
|
2016-02-04 11:59:06 -08:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn cast_bool_to_int() {
|
|
|
|
const t = true;
|
|
|
|
const f = false;
|
2016-02-09 17:50:53 -08:00
|
|
|
assert(i32(t) == i32(1));
|
|
|
|
assert(i32(f) == i32(0));
|
2016-02-04 11:59:06 -08:00
|
|
|
non_const_cast_bool_to_int(t, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn non_const_cast_bool_to_int(t: bool, f: bool) {
|
2016-02-09 17:50:53 -08:00
|
|
|
assert(i32(t) == i32(1));
|
|
|
|
assert(i32(f) == i32(0));
|
2016-02-04 11:59:06 -08:00
|
|
|
}
|
2016-02-04 14:50:06 -08:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn switch_on_enum() {
|
|
|
|
const fruit = Fruit.Orange;
|
|
|
|
non_const_switch_on_enum(fruit);
|
|
|
|
}
|
|
|
|
enum Fruit {
|
|
|
|
Apple,
|
|
|
|
Orange,
|
|
|
|
Banana,
|
|
|
|
}
|
|
|
|
fn non_const_switch_on_enum(fruit: Fruit) {
|
|
|
|
switch (fruit) {
|
2016-02-04 15:09:06 -08:00
|
|
|
Apple => unreachable{},
|
|
|
|
Orange => {},
|
|
|
|
Banana => unreachable{},
|
2016-02-04 14:50:06 -08:00
|
|
|
}
|
|
|
|
}
|
2016-02-04 15:09:06 -08:00
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn switch_statement() {
|
2016-02-11 17:33:04 -08:00
|
|
|
non_const_switch(SwitchStatmentFoo.C);
|
|
|
|
}
|
|
|
|
fn non_const_switch(foo: SwitchStatmentFoo) {
|
2016-02-04 15:09:06 -08:00
|
|
|
const val: i32 = switch (foo) {
|
|
|
|
A => 1,
|
|
|
|
B => 2,
|
|
|
|
C => 3,
|
|
|
|
D => 4,
|
|
|
|
};
|
|
|
|
if (val != 3) unreachable{};
|
|
|
|
}
|
|
|
|
enum SwitchStatmentFoo {
|
|
|
|
A,
|
|
|
|
B,
|
|
|
|
C,
|
|
|
|
D,
|
|
|
|
}
|
2016-02-04 16:21:08 -08:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn switch_prong_with_var() {
|
|
|
|
switch_prong_with_var_fn(SwitchProngWithVarEnum.One(13));
|
|
|
|
switch_prong_with_var_fn(SwitchProngWithVarEnum.Two(13.0));
|
|
|
|
switch_prong_with_var_fn(SwitchProngWithVarEnum.Meh);
|
|
|
|
}
|
|
|
|
enum SwitchProngWithVarEnum {
|
|
|
|
One: i32,
|
|
|
|
Two: f32,
|
|
|
|
Meh,
|
|
|
|
}
|
|
|
|
fn switch_prong_with_var_fn(a: SwitchProngWithVarEnum) {
|
|
|
|
switch(a) {
|
|
|
|
One => |x| {
|
|
|
|
if (x != 13) unreachable{};
|
|
|
|
},
|
|
|
|
Two => |x| {
|
|
|
|
if (x != 13.0) unreachable{};
|
|
|
|
},
|
|
|
|
Meh => |x| {
|
|
|
|
const v: void = x;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2016-02-06 18:16:01 -08:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn err_return_in_assignment() {
|
|
|
|
%%do_err_return_in_assignment();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn do_err_return_in_assignment() -> %void {
|
|
|
|
var x : i32 = undefined;
|
|
|
|
x = %return make_a_non_err();
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_a_non_err() -> %i32 {
|
|
|
|
return 1;
|
|
|
|
}
|
2016-02-06 18:35:33 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn rhs_maybe_unwrap_return() {
|
|
|
|
const x = ?true;
|
|
|
|
const y = x ?? return;
|
|
|
|
}
|
2016-02-06 23:23:05 -08:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn implicit_cast_fn_unreachable_return() {
|
|
|
|
wants_fn_with_void(fn_with_unreachable);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wants_fn_with_void(f: fn()) { }
|
|
|
|
|
|
|
|
fn fn_with_unreachable() -> unreachable {
|
|
|
|
unreachable {}
|
|
|
|
}
|
2016-02-07 00:25:04 -08:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn explicit_cast_maybe_pointers() {
|
|
|
|
const a: ?&i32 = undefined;
|
|
|
|
const b: ?&f32 = (?&f32)(a);
|
|
|
|
}
|
2016-02-07 11:38:51 -08:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn const_expr_eval_on_single_expr_blocks() {
|
|
|
|
if (const_expr_eval_on_single_expr_blocks_fn(1, true) != 3) unreachable{}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn const_expr_eval_on_single_expr_blocks_fn(x: i32, b: bool) -> i32 {
|
|
|
|
const literal = 3;
|
|
|
|
|
|
|
|
const result = if (b) {
|
|
|
|
literal
|
|
|
|
} else {
|
|
|
|
x
|
|
|
|
};
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2016-02-07 14:11:20 -08:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn builtin_const_eval() {
|
|
|
|
const x : i32 = @const_eval(1 + 2 + 3);
|
2016-02-09 17:50:53 -08:00
|
|
|
assert(x == @const_eval(6));
|
2016-02-07 14:11:20 -08:00
|
|
|
}
|
2016-02-07 14:43:19 -08:00
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn slicing() {
|
|
|
|
var array : [20]i32 = undefined;
|
|
|
|
|
|
|
|
array[5] = 1234;
|
|
|
|
|
|
|
|
var slice = array[5...10];
|
|
|
|
|
|
|
|
if (slice.len != 5) unreachable{};
|
|
|
|
|
|
|
|
const ptr = &slice[0];
|
|
|
|
if (ptr[0] != 1234) unreachable{};
|
|
|
|
|
|
|
|
var slice_rest = array[10...];
|
|
|
|
if (slice_rest.len != 10) unreachable{};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn memcpy_and_memset_intrinsics() {
|
|
|
|
var foo : [20]u8 = undefined;
|
|
|
|
var bar : [20]u8 = undefined;
|
|
|
|
|
|
|
|
@memset(&foo[0], 'A', foo.len);
|
|
|
|
@memcpy(&bar[0], &foo[0], bar.len);
|
|
|
|
|
|
|
|
if (bar[11] != 'A') unreachable{};
|
|
|
|
}
|
2016-02-07 14:52:52 -08:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn array_dot_len_const_expr() { }
|
|
|
|
struct ArrayDotLenConstExpr {
|
|
|
|
y: [@const_eval(some_array.len)]u8,
|
|
|
|
}
|
|
|
|
const some_array = []u8 {0, 1, 2, 3};
|
2016-02-09 17:50:53 -08:00
|
|
|
|
|
|
|
|
2016-02-13 11:50:13 -08:00
|
|
|
#attribute("test")
|
|
|
|
fn count_leading_zeroes() {
|
|
|
|
assert(@clz(u8, 0b00001010) == 4);
|
|
|
|
assert(@clz(u8, 0b10001010) == 0);
|
|
|
|
assert(@clz(u8, 0b00000000) == 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn count_trailing_zeroes() {
|
|
|
|
assert(@ctz(u8, 0b10100000) == 5);
|
|
|
|
assert(@ctz(u8, 0b10001010) == 1);
|
|
|
|
assert(@ctz(u8, 0b00000000) == 8);
|
|
|
|
}
|
|
|
|
|
2016-02-09 17:50:53 -08:00
|
|
|
|
2016-04-03 18:44:17 -07:00
|
|
|
#attribute("test")
|
|
|
|
fn multiline_string() {
|
|
|
|
const s1 = r"AOEU(
|
|
|
|
one
|
|
|
|
two)
|
|
|
|
three)AOEU";
|
|
|
|
const s2 = "\none\ntwo)\nthree";
|
|
|
|
const s3 = r"(
|
|
|
|
one
|
|
|
|
two)
|
|
|
|
three)";
|
|
|
|
assert(str_eql(s1, s2));
|
|
|
|
assert(str_eql(s3, s2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-09 17:50:53 -08:00
|
|
|
|
2016-04-06 11:38:12 -07:00
|
|
|
#attribute("test")
|
|
|
|
fn simple_generic_fn() {
|
|
|
|
assert(max(i32)(3, -1) == 3);
|
2016-04-07 10:34:54 -07:00
|
|
|
assert(max(f32)(0.123, 0.456) == 0.456);
|
2016-04-07 11:34:04 -07:00
|
|
|
assert(add(2)(3) == 5);
|
2016-04-06 11:38:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn max(T: type)(a: T, b: T) -> T {
|
|
|
|
return if (a > b) a else b;
|
|
|
|
}
|
|
|
|
|
2016-04-07 11:34:04 -07:00
|
|
|
fn add(a: i32)(b: i32) -> i32 {
|
|
|
|
return a + b;
|
|
|
|
}
|
|
|
|
|
2016-04-06 11:38:12 -07:00
|
|
|
|
2016-04-06 14:08:23 -07:00
|
|
|
#attribute("test")
|
|
|
|
fn constant_equal_function_pointers() {
|
|
|
|
const alias = empty_fn;
|
|
|
|
assert(@const_eval(empty_fn == alias));
|
|
|
|
}
|
|
|
|
|
|
|
|
fn empty_fn() {}
|
|
|
|
|
2016-04-07 10:34:54 -07:00
|
|
|
#attribute("test")
|
|
|
|
fn generic_function_equality() {
|
|
|
|
assert(max(i32) == max(i32));
|
|
|
|
}
|
|
|
|
|
2016-04-06 14:08:23 -07:00
|
|
|
|
2016-04-07 15:09:55 -07:00
|
|
|
#attribute("test")
|
|
|
|
fn generic_malloc_free() {
|
|
|
|
const a = %%mem_alloc(u8)(10);
|
|
|
|
mem_free(u8)(a);
|
|
|
|
}
|
|
|
|
const some_mem : [100]u8 = undefined;
|
|
|
|
fn mem_alloc(T: type)(n: isize) -> %[]T {
|
|
|
|
return (&T)(&some_mem[0])[0...n];
|
|
|
|
}
|
|
|
|
fn mem_free(T: type)(mem: []T) { }
|
|
|
|
|
|
|
|
|
2016-04-08 17:08:50 -07:00
|
|
|
#attribute("test")
|
|
|
|
fn call_fn_with_empty_string() {
|
|
|
|
accepts_string("");
|
|
|
|
}
|
|
|
|
|
|
|
|
fn accepts_string(foo: []u8) { }
|
2016-04-08 17:30:26 -07:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn hex_escape() {
|
|
|
|
assert(str_eql("\x68\x65\x6c\x6c\x6f", "hello"));
|
|
|
|
}
|
2016-04-09 08:55:53 -07:00
|
|
|
|
|
|
|
|
|
|
|
error AnError;
|
|
|
|
error ALongerErrorName;
|
|
|
|
#attribute("test")
|
|
|
|
fn error_name_string() {
|
|
|
|
assert(str_eql(@err_name(error.AnError), "AnError"));
|
|
|
|
assert(str_eql(@err_name(error.ALongerErrorName), "ALongerErrorName"));
|
|
|
|
}
|
2016-04-09 16:41:17 -07:00
|
|
|
|
|
|
|
|
|
|
|
#attribute("test")
|
|
|
|
fn goto_and_labels() {
|
|
|
|
goto_loop();
|
|
|
|
assert(goto_counter == 10);
|
|
|
|
}
|
|
|
|
fn goto_loop() {
|
|
|
|
var i: i32 = 0;
|
|
|
|
goto cond;
|
|
|
|
loop:
|
|
|
|
i += 1;
|
|
|
|
cond:
|
|
|
|
if (!(i < 10)) goto end;
|
|
|
|
goto_counter += 1;
|
|
|
|
goto loop;
|
|
|
|
end:
|
|
|
|
}
|
|
|
|
var goto_counter: i32 = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-09 17:26:04 -07:00
|
|
|
#attribute("test")
|
|
|
|
fn goto_leave_defer_scope() {
|
|
|
|
test_goto_leave_defer_scope(true);
|
|
|
|
}
|
|
|
|
fn test_goto_leave_defer_scope(b: bool) {
|
|
|
|
var it_worked = false;
|
|
|
|
|
|
|
|
goto entry;
|
|
|
|
exit:
|
|
|
|
if (it_worked) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
unreachable{};
|
|
|
|
entry:
|
|
|
|
defer it_worked = true;
|
|
|
|
if (b) goto exit;
|
|
|
|
}
|
|
|
|
|