1const builtin = @import("builtin");
2const std = @import("std");
3
4const c = std.c;
5const testing = std.testing;
6
7/// Not defined in `std.c` because C headers don't either.
8const Node = extern struct {
9 next: ?*Node,
10 prev: ?*Node,
11};
12
13test "insque and remque" {
14 if (builtin.target.os.tag == .windows) return; // no insque/remque
15
16 var first: Node = .{ .next = null, .prev = null };
17 var second: Node = .{ .next = null, .prev = null };
18 var third: Node = .{ .next = null, .prev = null };
19
20 c.insque(&first, null);
21 try testing.expectEqual(@as(?*Node, null), first.next);
22 try testing.expectEqual(@as(?*Node, null), first.prev);
23
24 c.insque(&second, &first);
25 try testing.expectEqual(@as(?*Node, &second), first.next);
26 try testing.expectEqual(@as(?*Node, &first), second.prev);
27
28 c.insque(&third, &first);
29 try testing.expectEqual(@as(?*Node, &third), first.next);
30 try testing.expectEqual(@as(?*Node, &second), third.next);
31 try testing.expectEqual(@as(?*Node, &first), third.prev);
32 try testing.expectEqual(@as(?*Node, &third), second.prev);
33
34 c.remque(&third);
35 try testing.expectEqual(@as(?*Node, &second), first.next);
36 try testing.expectEqual(@as(?*Node, &first), second.prev);
37
38 c.remque(&second);
39 try testing.expectEqual(@as(?*Node, null), first.next);
40}