Skip to content

Commit 46fcf58

Browse files
committed
Add test to EnumMap too
1 parent ea6946c commit 46fcf58

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/std/enums.zig

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ pub fn EnumMap(comptime E: type, comptime V: type) type {
792792

793793
pub fn next(self: *Iterator) ?Entry {
794794
return if (self.inner.next()) |index|
795-
Entry{
795+
.{
796796
.key = Indexer.keyForIndex(index),
797797
.value = &self.values[index],
798798
}
@@ -816,6 +816,19 @@ test EnumMap {
816816
try testing.expectEqual(0x80, some.get(.blue));
817817
}
818818

819+
test "EnumMap iterator for one field" {
820+
const Enum0 = std.meta.FieldEnum(struct { x: u32 });
821+
const Enum1 = enum { x };
822+
823+
var a = std.EnumMap(Enum0, u32).initFull(123);
824+
var it0 = a.iterator();
825+
try testing.expectEqual(it0.next().?.key, Enum0.x);
826+
827+
var b = std.EnumMap(Enum1, u32).initFull(123);
828+
var it1 = b.iterator();
829+
try testing.expectEqual(it1.next().?.key, Enum1.x);
830+
}
831+
819832
/// A multiset of enum elements up to a count of usize. Backed
820833
/// by an EnumArray. This type does no dynamic allocation and can
821834
/// be copied by value.
@@ -1292,7 +1305,7 @@ pub fn EnumArray(comptime E: type, comptime V: type) type {
12921305
key: Key,
12931306

12941307
/// A pointer to the value in the array associated
1295-
/// with this key. Modifications through this
1308+
/// with this key. Modifications through this
12961309
/// pointer will modify the underlying data.
12971310
value: *Value,
12981311
};

0 commit comments

Comments
 (0)