aboutsummaryrefslogtreecommitdiff
path: root/test/cases/error.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-04-30 20:35:54 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-04-30 20:35:54 -0400
commita35b366eb64272c6d4646aedc035a837ed0c3cb0 (patch)
treedcde18b655e59df2b24f6804eb069f3f43393b28 /test/cases/error.zig
parent76ab1d2b6c9eedd861920ae6b6f8ee06aa482159 (diff)
downloadzig-a35b366eb64272c6d4646aedc035a837ed0c3cb0.tar.gz
zig-a35b366eb64272c6d4646aedc035a837ed0c3cb0.zip
[breaking] delete ptr deref prefix op
start using zig-fmt-pointer-reform branch build of zig fmt to fix code to use the new syntax all of test/cases/* are processed, but there are more left to be done - all the std lib used by the behavior tests
Diffstat (limited to 'test/cases/error.zig')
-rw-r--r--test/cases/error.zig56
1 files changed, 30 insertions, 26 deletions
diff --git a/test/cases/error.zig b/test/cases/error.zig
index 2a1433df5b..70d96e4d01 100644
--- a/test/cases/error.zig
+++ b/test/cases/error.zig
@@ -30,14 +30,12 @@ test "@errorName" {
assert(mem.eql(u8, @errorName(error.ALongerErrorName), "ALongerErrorName"));
}
-
test "error values" {
const a = i32(error.err1);
const b = i32(error.err2);
assert(a != b);
}
-
test "redefinition of error values allowed" {
shouldBeNotEqual(error.AnError, error.SecondError);
}
@@ -45,7 +43,6 @@ fn shouldBeNotEqual(a: error, b: error) void {
if (a == b) unreachable;
}
-
test "error binary operator" {
const a = errBinaryOperatorG(true) catch 3;
const b = errBinaryOperatorG(false) catch 3;
@@ -56,20 +53,20 @@ fn errBinaryOperatorG(x: bool) error!isize {
return if (x) error.ItBroke else isize(10);
}
-
test "unwrap simple value from error" {
const i = unwrapSimpleValueFromErrorDo() catch unreachable;
assert(i == 13);
}
-fn unwrapSimpleValueFromErrorDo() error!isize { return 13; }
-
+fn unwrapSimpleValueFromErrorDo() error!isize {
+ return 13;
+}
test "error return in assignment" {
doErrReturnInAssignment() catch unreachable;
}
fn doErrReturnInAssignment() error!void {
- var x : i32 = undefined;
+ var x: i32 = undefined;
x = try makeANonErr();
}
@@ -95,7 +92,10 @@ test "error set type " {
comptime testErrorSetType();
}
-const MyErrSet = error {OutOfMemory, FileNotFound};
+const MyErrSet = error {
+ OutOfMemory,
+ FileNotFound,
+};
fn testErrorSetType() void {
assert(@memberCount(MyErrSet) == 2);
@@ -109,14 +109,19 @@ fn testErrorSetType() void {
}
}
-
test "explicit error set cast" {
testExplicitErrorSetCast(Set1.A);
comptime testExplicitErrorSetCast(Set1.A);
}
-const Set1 = error{A, B};
-const Set2 = error{A, C};
+const Set1 = error {
+ A,
+ B,
+};
+const Set2 = error {
+ A,
+ C,
+};
fn testExplicitErrorSetCast(set1: Set1) void {
var x = Set2(set1);
@@ -129,7 +134,8 @@ test "comptime test error for empty error set" {
comptime testComptimeTestErrorEmptySet(1234);
}
-const EmptyErrorSet = error {};
+const EmptyErrorSet = error {
+};
fn testComptimeTestErrorEmptySet(x: EmptyErrorSet!i32) void {
if (x) |v| assert(v == 1234) else |err| @compileError("bad");
@@ -145,7 +151,9 @@ test "comptime err to int of error set with only 1 possible value" {
testErrToIntWithOnePossibleValue(error.A, u32(error.A));
comptime testErrToIntWithOnePossibleValue(error.A, u32(error.A));
}
-fn testErrToIntWithOnePossibleValue(x: error{A}, comptime value: u32) void {
+fn testErrToIntWithOnePossibleValue(x: error {
+ A,
+}, comptime value: u32) void {
if (u32(x) != value) {
@compileError("bad");
}
@@ -176,7 +184,6 @@ fn quux_1() !i32 {
return error.C;
}
-
test "error: fn returning empty error set can be passed as fn returning any error" {
entry();
comptime entry();
@@ -186,24 +193,24 @@ fn entry() void {
foo2(bar2);
}
-fn foo2(f: fn()error!void) void {
+fn foo2(f: fn() error!void) void {
const x = f();
}
-fn bar2() (error{}!void) { }
-
+fn bar2() (error {
+}!void) {}
test "error: Zero sized error set returned with value payload crash" {
_ = foo3(0);
_ = comptime foo3(0);
}
-const Error = error{};
+const Error = error {
+};
fn foo3(b: usize) Error!usize {
return b;
}
-
test "error: Infer error set from literals" {
_ = nullLiteral("n") catch |err| handleErrors(err);
_ = floatLiteral("n") catch |err| handleErrors(err);
@@ -215,29 +222,26 @@ test "error: Infer error set from literals" {
fn handleErrors(err: var) noreturn {
switch (err) {
- error.T => {}
+ error.T => {},
}
unreachable;
}
fn nullLiteral(str: []const u8) !?i64 {
- if (str[0] == 'n')
- return null;
+ if (str[0] == 'n') return null;
return error.T;
}
fn floatLiteral(str: []const u8) !?f64 {
- if (str[0] == 'n')
- return 1.0;
+ if (str[0] == 'n') return 1.0;
return error.T;
}
fn intLiteral(str: []const u8) !?i64 {
- if (str[0] == 'n')
- return 1;
+ if (str[0] == 'n') return 1;
return error.T;
}