port more tests
parent
ba8af0f1e2
commit
8dc45bc505
|
@ -1,17 +0,0 @@
|
|||
const assert = @import("std").debug.assert;
|
||||
|
||||
fn maybeReturn() {
|
||||
@setFnTest(this, true);
|
||||
|
||||
assert(??foo(1235));
|
||||
assert(if (const _ ?= foo(null)) false else true);
|
||||
assert(!??foo(1234));
|
||||
}
|
||||
|
||||
// TODO test static eval maybe return
|
||||
fn foo(x: ?i32) -> ?bool {
|
||||
@setFnStaticEval(this, false);
|
||||
|
||||
const value = ?return x;
|
||||
return value > 1234;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
const assert = @import("std").debug.assert;
|
||||
|
||||
pub fn List(inline T: type) -> type {
|
||||
SmallList(T, 8)
|
||||
}
|
||||
|
||||
pub struct SmallList(inline T: type, inline STATIC_SIZE: usize) {
|
||||
items: []T,
|
||||
length: usize,
|
||||
prealloc_items: [STATIC_SIZE]T,
|
||||
}
|
||||
|
||||
fn functionWithReturnTypeType() {
|
||||
@setFnTest(this, true);
|
||||
|
||||
var list: List(i32) = undefined;
|
||||
var list2: List(i32) = undefined;
|
||||
list.length = 10;
|
||||
list2.length = 10;
|
||||
assert(list.prealloc_items.len == 8);
|
||||
assert(list2.prealloc_items.len == 8);
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
const assert = @import("std").debug.assert;
|
||||
|
||||
fn varParams() {
|
||||
@setFnTest(this, true);
|
||||
|
||||
assert(max_i32(12, 34) == 34);
|
||||
assert(max_f64(1.2, 3.4) == 3.4);
|
||||
|
||||
assert(max_i32_noeval(12, 34) == 34);
|
||||
assert(max_f64_noeval(1.2, 3.4) == 3.4);
|
||||
}
|
||||
|
||||
fn max(a: var, b: var) -> @typeOf(a) {
|
||||
if (a > b) a else b
|
||||
}
|
||||
|
||||
fn max_i32(a: i32, b: i32) -> i32 {
|
||||
max(a, b)
|
||||
}
|
||||
|
||||
fn max_f64(a: f64, b: f64) -> f64 {
|
||||
max(a, b)
|
||||
}
|
||||
|
||||
fn max_i32_noeval(a: i32, b: i32) -> i32 {
|
||||
@setFnStaticEval(this, false);
|
||||
|
||||
max(a, b)
|
||||
}
|
||||
|
||||
fn max_f64_noeval(a: f64, b: f64) -> f64 {
|
||||
@setFnStaticEval(this, false);
|
||||
|
||||
max(a, b)
|
||||
}
|
|
@ -52,6 +52,25 @@ const statically_added_number = staticAdd(1, 2);
|
|||
fn staticAdd(a: i32, b: i32) -> i32 { a + b }
|
||||
|
||||
|
||||
fn constExprEvalOnSingleExprBlocks() {
|
||||
@setFnTest(this);
|
||||
|
||||
assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
|
||||
}
|
||||
|
||||
fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 {
|
||||
const literal = 3;
|
||||
|
||||
const result = if (b) {
|
||||
literal
|
||||
} else {
|
||||
x
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -73,6 +73,19 @@ fn @"weird function name"() {
|
|||
@setFnTest(this);
|
||||
}
|
||||
|
||||
fn implicitCastFnUnreachableReturn() {
|
||||
@setFnTest(this);
|
||||
|
||||
wantsFnWithVoid(fnWithUnreachable);
|
||||
}
|
||||
|
||||
fn wantsFnWithVoid(f: fn()) { }
|
||||
|
||||
fn fnWithUnreachable() -> unreachable {
|
||||
@unreachable()
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO const assert = @import("std").debug.assert;
|
||||
fn assert(ok: bool) {
|
||||
|
|
|
@ -64,6 +64,30 @@ fn max_f64(a: f64, b: f64) -> f64 {
|
|||
max_var(a, b)
|
||||
}
|
||||
|
||||
|
||||
pub fn List(inline T: type) -> type {
|
||||
SmallList(T, 8)
|
||||
}
|
||||
|
||||
pub fn SmallList(inline T: type, inline STATIC_SIZE: usize) -> type {
|
||||
struct {
|
||||
items: []T,
|
||||
length: usize,
|
||||
prealloc_items: [STATIC_SIZE]T,
|
||||
}
|
||||
}
|
||||
|
||||
fn functionWithReturnTypeType() {
|
||||
@setFnTest(this);
|
||||
|
||||
var list: List(i32) = undefined;
|
||||
var list2: List(i32) = undefined;
|
||||
list.length = 10;
|
||||
list2.length = 10;
|
||||
assert(list.prealloc_items.len == 8);
|
||||
assert(list2.prealloc_items.len == 8);
|
||||
}
|
||||
|
||||
// TODO const assert = @import("std").debug.assert;
|
||||
fn assert(ok: bool) {
|
||||
if (!ok)
|
||||
|
|
|
@ -230,6 +230,18 @@ fn stringEscapes() {
|
|||
assert(memeql("\u1234\u0069", "\xe1\x88\xb4\x69"));
|
||||
}
|
||||
|
||||
fn multilineString() {
|
||||
@setFnTest(this);
|
||||
|
||||
const s1 =
|
||||
\\one
|
||||
\\two)
|
||||
\\three
|
||||
;
|
||||
const s2 = "one\ntwo)\nthree";
|
||||
assert(memeql(s1, s2));
|
||||
}
|
||||
|
||||
|
||||
// TODO import from std.str
|
||||
pub fn memeql(a: []const u8, b: []const u8) -> bool {
|
||||
|
|
|
@ -38,6 +38,27 @@ fn assignToIfVarPtr() {
|
|||
assert(??maybe_bool == false);
|
||||
}
|
||||
|
||||
fn rhsMaybeUnwrapReturn() {
|
||||
@setFnTest(this);
|
||||
|
||||
const x: ?bool = true;
|
||||
const y = x ?? return;
|
||||
}
|
||||
|
||||
|
||||
fn maybeReturn() {
|
||||
@setFnTest(this);
|
||||
|
||||
assert(??foo(1235));
|
||||
assert(if (const _ ?= foo(null)) false else true);
|
||||
assert(!??foo(1234));
|
||||
}
|
||||
|
||||
// TODO test static eval maybe return
|
||||
fn foo(x: ?i32) -> ?bool {
|
||||
const value = ?return x;
|
||||
return value > 1234;
|
||||
}
|
||||
|
||||
// TODO const assert = @import("std").debug.assert;
|
||||
fn assert(ok: bool) {
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
const assert = @import("std").debug.assert;
|
||||
|
||||
fn sizeofAndTypeOf() {
|
||||
@setFnTest(this, true);
|
||||
@setFnTest(this);
|
||||
|
||||
const y: @typeOf(x) = 120;
|
||||
assert(@sizeOf(@typeOf(y)) == 2);
|
||||
}
|
||||
const x: u16 = 13;
|
||||
const z: @typeOf(x) = 19;
|
||||
|
||||
// TODO const assert = @import("std").debug.assert;
|
||||
fn assert(ok: bool) {
|
||||
if (!ok)
|
||||
@unreachable();
|
||||
}
|
|
@ -2,36 +2,10 @@ const std = @import("std");
|
|||
const assert = std.debug.assert;
|
||||
const str = std.str;
|
||||
const cstr = std.cstr;
|
||||
const test_return_type_type = @import("cases/return_type_type.zig");
|
||||
const test_sizeof_and_typeof = @import("cases/sizeof_and_typeof.zig");
|
||||
const test_maybe_return = @import("cases/maybe_return.zig");
|
||||
const test_var_params = @import("cases/var_params.zig");
|
||||
const test_const_slice_child = @import("cases/const_slice_child.zig");
|
||||
const test_switch_prong_implicit_cast = @import("cases/switch_prong_implicit_cast.zig");
|
||||
const test_switch_prong_err_enum = @import("cases/switch_prong_err_enum.zig");
|
||||
const test_enum_with_members = @import("cases/enum_with_members.zig");
|
||||
const test_struct_contains_slice_of_itself = @import("cases/struct_contains_slice_of_itself.zig");
|
||||
|
||||
|
||||
fn rhsMaybeUnwrapReturn() {
|
||||
@setFnTest(this, true);
|
||||
|
||||
const x = ?true;
|
||||
const y = x ?? return;
|
||||
}
|
||||
|
||||
|
||||
fn implicitCastFnUnreachableReturn() {
|
||||
@setFnTest(this, true);
|
||||
|
||||
wantsFnWithVoid(fnWithUnreachable);
|
||||
}
|
||||
|
||||
fn wantsFnWithVoid(f: fn()) { }
|
||||
|
||||
fn fnWithUnreachable() -> unreachable {
|
||||
@unreachable()
|
||||
}
|
||||
|
||||
|
||||
fn explicitCastMaybePointers() {
|
||||
|
@ -42,39 +16,8 @@ fn explicitCastMaybePointers() {
|
|||
}
|
||||
|
||||
|
||||
fn constExprEvalOnSingleExprBlocks() {
|
||||
@setFnTest(this, true);
|
||||
|
||||
assert(constExprEvalOnSingleExprBlocksFn(1, true) == 3);
|
||||
}
|
||||
|
||||
fn constExprEvalOnSingleExprBlocksFn(x: i32, b: bool) -> i32 {
|
||||
const literal = 3;
|
||||
|
||||
const result = if (b) {
|
||||
literal
|
||||
} else {
|
||||
x
|
||||
};
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
fn multilineString() {
|
||||
@setFnTest(this, true);
|
||||
|
||||
const s1 =
|
||||
\\one
|
||||
\\two)
|
||||
\\three
|
||||
;
|
||||
const s2 = "one\ntwo)\nthree";
|
||||
assert(str.eql(s1, s2));
|
||||
}
|
||||
|
||||
fn multilineCString() {
|
||||
@setFnTest(this, true);
|
||||
@setFnTest(this);
|
||||
|
||||
const s1 =
|
||||
c\\one
|
||||
|
|
|
@ -16,8 +16,9 @@ const test_import = @import("cases3/import.zig");
|
|||
const test_math = @import("cases3/math.zig");
|
||||
const test_misc = @import("cases3/misc.zig");
|
||||
const test_null = @import("cases3/null.zig");
|
||||
const test_sizeof_and_typeof = @import("cases3/sizeof_and_typeof.zig");
|
||||
const test_struct = @import("cases3/struct.zig");
|
||||
const test_struct_contains_slice_of_itself = @import("cases3/struct_contains_slice_of_itself.zig");
|
||||
const test_switch = @import("cases3/switch.zig");
|
||||
const test_this = @import("cases3/this.zig");
|
||||
const test_while = @import("cases3/while.zig");
|
||||
const test_struct_contains_slice_of_itself = @import("cases3/struct_contains_slice_of_itself.zig");
|
||||
|
|
Loading…
Reference in New Issue