mirror of
https://github.com/ziglang/zig.git
synced 2025-12-24 15:13:08 +00:00
41 lines
917 B
Zig
41 lines
917 B
Zig
const std = @import("std");
|
|
const testing = std.testing;
|
|
const mem = std.mem;
|
|
const expect = testing.expect;
|
|
const expectEqual = testing.expectEqual;
|
|
|
|
test "arrays" {
|
|
var array: [5]u32 = undefined;
|
|
|
|
var i: u32 = 0;
|
|
while (i < 5) {
|
|
array[i] = i + 1;
|
|
i = array[i];
|
|
}
|
|
|
|
i = 0;
|
|
var accumulator = @as(u32, 0);
|
|
while (i < 5) {
|
|
accumulator += array[i];
|
|
|
|
i += 1;
|
|
}
|
|
|
|
try expect(accumulator == 15);
|
|
try expect(getArrayLen(&array) == 5);
|
|
}
|
|
fn getArrayLen(a: []const u32) usize {
|
|
return a.len;
|
|
}
|
|
|
|
test "array init with mult" {
|
|
const a = 'a';
|
|
var i: [8]u8 = [2]u8{ a, 'b' } ** 4;
|
|
try expect(std.mem.eql(u8, &i, "abababab"));
|
|
|
|
// this should cause a Value.repeated to be emitted in AIR.
|
|
// TODO: find a way to test that this is actually getting emmited
|
|
var j: [4]u8 = [1]u8{'a'} ** 4;
|
|
try expect(std.mem.eql(u8, &j, "aaaa"));
|
|
}
|