commit d89d6374bed73683fa92d3c409016fb3f260a7c1 (tree)
parent 8fa29bc0a235fb123c02e89936d0699906831a37
Author: daurnimator <quae@daurnimator.com>
Date: Thu, 19 Nov 2020 00:57:54 +1100
std: add tests for std.atomic.Int
Diffstat:
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git 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);
+}