Skip to content

Latest commit

 

History

History
183 lines (153 loc) · 4.36 KB

ob-zig-test.org

File metadata and controls

183 lines (153 loc) · 4.36 KB

a collection of examples for ob-zig tests

Simple tests

const stdout = std.io.getStdOut().writer();
try stdout.print("{s}", .{"hello"});
const stdout = std.io.getStdOut().writer();
try stdout.print("{}", .{q});
const stdout = std.io.getStdOut().writer();
var p_plus_q: isize = p + q;
try stdout.print("{}", .{p_plus_q});
const stdout = std.io.getStdOut().writer();
try stdout.print("{s} {d}", .{q, q.len});

Tests zig tests

test "simple test" {
  const stdout = std.io.getStdOut().writer();
  const hello = "hello";

  try std.testing.expectEqual("hello", hello);
  try stdout.print("{s}", .{hello});
}
fn helloFn() []const u8 {
    return "hello";
}

test "fn test" {
    const stdout = std.io.getStdOut().writer();
    var hello = helloFn();

    try std.testing.expectEqualStrings("hello", hello);
    try stdout.print("{s}", .{hello});
}
fn helloFn() []const u8 {
    return "hello";
}

test "fn test" {
    const stdout = std.io.getStdOut().writer();
    var hello = helloFn();

    try std.testing.expectEqualStrings("hello", hello);
    try stdout.print("{s}", .{hello});
}

test "simple test" {
  const stdout = std.io.getStdOut().writer();
  var hello = "hello";

  try std.testing.expectEqual("hello", hello);
  try stdout.print("{s}", .{hello});
}

List var

const stdout = std.io.getStdOut().writer();
try stdout.print("{s}{s}{d}", .{a[0], a[1], a.len});

Integer table

AB
12
34
const stdout = std.io.getStdOut().writer();

pub fn main() !void {
    for (int_table) |row| {
        for (row) |field| {
            try stdout.print("{d} ", .{ field });
        }
        try stdout.print("\n", .{});
    }
    try stdout.print("A1 {d}\n", .{int_table_h(1, "A")});
    try stdout.print("B0 {d}\n", .{int_table_h(0, "B")});
}

Float table

AB
1.12.2
3.54.7
const stdout = std.io.getStdOut().writer();

pub fn main() !void {
    for (float_table) |row| {
        for (row) |field| {
            try stdout.print("{d} ", .{ field });
        }
        try stdout.print("\n", .{});
    }
    try stdout.print("A1 {d}\n", .{float_table_h(1, "A")});
    try stdout.print("B0 {d}\n", .{float_table_h(0, "B")});
}

Mixed table

dayquantity
monday34
tuesday41
wednesday56
thursday17
friday12
saturday7
sunday4
const stdout = std.io.getStdOut().writer();

pub fn main() !void {
    for (mixed_table) |row| {
        for (row) |field| {
            try stdout.print("{s} ", .{ field });
        }
        try stdout.print("\n", .{});
    }
    try stdout.print("tuesday_qty {s}\n", .{mixed_table_h(1, "quantity")});
    try stdout.print("day_idx_4 {s}\n", .{mixed_table_h(4, "day")});
}