From d89d6374bed73683fa92d3c409016fb3f260a7c1 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 19 Nov 2020 00:57:54 +1100 Subject: [PATCH] std: add tests for std.atomic.Int --- lib/std/atomic/int.zig | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/std/atomic/int.zig b/lib/std/atomic/int.zig index 5e58e17abb..155a340b0a 100644 --- a/lib/std/atomic/int.zig +++ b/lib/std/atomic/int.zig @@ -4,7 +4,9 @@ // The MIT license requires this copyright notice to be included in all copies // and substantial portions of the software. -const builtin = @import("std").builtin; +const std = @import("std"); +const builtin = std.builtin; +const testing = std.testing; /// Thread-safe, lock-free integer pub fn Int(comptime T: type) type { @@ -61,3 +63,15 @@ pub fn Int(comptime T: type) type { } }; } + +test "std.atomic.Int" { + var a = Int(u8).init(0); + testing.expectEqual(@as(u8, 0), a.incr()); + testing.expectEqual(@as(u8, 1), a.load(.SeqCst)); + a.store(42, .SeqCst); + testing.expectEqual(@as(u8, 42), a.decr()); + testing.expectEqual(@as(u8, 41), a.xchg(100)); + testing.expectEqual(@as(u8, 100), a.fetchAdd(5)); + testing.expectEqual(@as(u8, 105), a.get()); + a.set(200); +}