commit 604d9918562b12c009981c1ce1884f9bdeedaaf5
parent 8978c6eae3accde2f7fc75204a9e18958e12c360
Author: Drew DeVault <sir@cmpwn.com>
Date: Tue, 12 Jan 2021 12:13:07 -0500
tests: use logical AND to consoldate assertions
Diffstat:
4 files changed, 24 insertions(+), 60 deletions(-)
diff --git a/tests/01-arrays.ha b/tests/01-arrays.ha
@@ -2,31 +2,19 @@ fn indexing() void = {
let x = [1, 2, 3];
let y = &x;
let z = &y;
- // TODO: Simplify these once we have logical and (&&)
- assert(x[0] == 1);
- assert(x[1] == 2);
- assert(x[2] == 3);
- assert(y[0] == 1);
- assert(y[1] == 2);
- assert(y[2] == 3);
- assert(z[0] == 1);
- assert(z[1] == 2);
- assert(z[2] == 3);
+ assert(x[0] == 1 && x[1] == 2 && x[2] == 3);
+ assert(y[0] == 1 && y[1] == 2 && y[2] == 3);
+ assert(z[0] == 1 && z[1] == 2 && z[2] == 3);
x[0] = 5;
x[1] = 6;
x[2] = 7;
- assert(x[0] == 5);
- assert(x[1] == 6);
- assert(x[2] == 7);
- assert(y[0] == 5);
- assert(y[1] == 6);
- assert(y[2] == 7);
+ assert(x[0] == 5 && x[1] == 6 && x[2] == 7);
+ assert(y[0] == 5 && y[1] == 6 && y[2] == 7);
let q = &x[0];
*q = 1337;
- assert(x[0] == 1337);
- assert(y[0] == 1337);
+ assert(x[0] == 1337 && y[0] == 1337);
};
fn measurements() void = {
@@ -55,12 +43,8 @@ fn assignment() void = {
let y = x;
let z = [0, 0, 0];
z = y;
- assert(y[0] == 1);
- assert(y[1] == 2);
- assert(y[2] == 3);
- assert(z[0] == 1);
- assert(z[1] == 2);
- assert(z[2] == 3);
+ assert(y[0] == 1 && y[1] == 2 && y[2] == 3);
+ assert(z[0] == 1 && z[1] == 2 && z[2] == 3);
};
fn param(x: [3]int) void = {
@@ -72,14 +56,11 @@ fn param(x: [3]int) void = {
fn nested() void = {
let x = [[1, 2], [3, 4]];
- assert(x[0][0] == 1);
- assert(x[0][1] == 2);
- assert(x[1][0] == 3);
- assert(x[1][1] == 4);
+ assert(x[0][0] == 1 && x[0][1] == 2);
+ assert(x[1][0] == 3 && x[1][1] == 4);
assert(len(x[0]) == 2z);
x[1] = [5, 6];
- assert(x[1][0] == 5);
- assert(x[1][1] == 6);
+ assert(x[1][0] == 5 && x[1][1] == 6);
};
export fn main() void = {
diff --git a/tests/04-strings.ha b/tests/04-strings.ha
@@ -25,8 +25,7 @@ fn storage() void = {
length: size,
capacity: size,
};
- assert(ptr.length == 15z);
- assert(ptr.capacity == 15z);
+ assert(ptr.length == 15z && ptr.capacity == 15z);
// UTF-8 encoded
const expected = [
diff --git a/tests/06-structs.ha b/tests/06-structs.ha
@@ -20,36 +20,29 @@ fn padding() void = {
fn storage() void = {
let coords = struct { x: i32 = 10i32, y: i32 = 20i32 };
let ptr = &coords: *[*]i32;
- assert(ptr[0] == 10i32);
- assert(ptr[1] == 20i32);
+ assert(ptr[0] == 10i32 && ptr[1] == 20i32);
};
fn assignment() void = {
let coords = struct { x: int = 20, y: int = 30 };
coords.x = 40;
coords.y = 50;
- assert(coords.x == 40);
- assert(coords.y == 50);
+ assert(coords.x == 40 && coords.y == 50);
coords = struct { x: int = 60, y: int = 70 };
- assert(coords.x == 60);
- assert(coords.y == 70);
+ assert(coords.x == 60 && coords.y == 70);
};
fn deref() void = {
let coords = struct { x: int = 20, y: int = 30 };
let a = &coords;
- assert(a.x == 20);
- assert(a.y == 30);
+ assert(a.x == 20 && a.y == 30);
let b = &a;
- assert(b.x == 20);
- assert(b.y == 30);
+ assert(b.x == 20 && b.y == 30);
let c = &b;
- assert(c.x == 20);
- assert(c.y == 30);
+ assert(c.x == 20 && c.y == 30);
c.x = 42;
c.y = 96;
- assert(coords.x == 42);
- assert(coords.y == 96);
+ assert(coords.x == 42 && coords.y == 96);
};
fn nested() void = {
diff --git a/tests/08-slices.ha b/tests/08-slices.ha
@@ -20,8 +20,7 @@ fn storage() void = {
};
assert(len(x) == 5z);
- assert(ptr.length == 5z);
- assert(ptr.capacity == 5z);
+ assert(ptr.length == 5z && ptr.capacity == 5z);
for (let i = 0z; i < len(expected); i += 1z) {
assert(x[i] == expected[i]);
@@ -41,23 +40,15 @@ fn assignment() void = {
x[0] = 4;
x[1] = 5;
x[2] = 6;
- assert(x[0] == 4);
- assert(x[1] == 5);
- assert(x[2] == 6);
- assert(source[0] == 4);
- assert(source[1] == 5);
- assert(source[2] == 6);
+ assert(x[0] == 4 && x[1] == 5 && x[2] == 6);
+ assert(source[0] == 4 && source[1] == 5 && source[2] == 6);
let y: []int = [4, 5, 6];
x = y;
x[0] = 7;
x[1] = 8;
x[2] = 9;
- assert(x[0] == 7);
- assert(x[1] == 8);
- assert(x[2] == 9);
- assert(source[0] == 4);
- assert(source[1] == 5);
- assert(source[2] == 6);
+ assert(x[0] == 7 && x[1] == 8 && x[2] == 9);
+ assert(source[0] == 4 && source[1] == 5 && source[2] == 6);
};
export fn main() void = {