@@ -980,6 +980,17 @@ test "pure EnumSet fns" {
980
980
try testing .expect (full .differenceWith (black ).eql (red ));
981
981
}
982
982
983
+ test "std.enums.EnumSet empty" {
984
+ const E = enum {};
985
+ const empty = EnumSet (E ).initEmpty ();
986
+ const full = EnumSet (E ).initFull ();
987
+
988
+ try std .testing .expect (empty .eql (full ));
989
+ try std .testing .expect (empty .complement ().eql (full ));
990
+ try std .testing .expect (empty .complement ().eql (full .complement ()));
991
+ try std .testing .expect (empty .eql (full .complement ()));
992
+ }
993
+
983
994
test "std.enums.EnumSet const iterator" {
984
995
const Direction = enum { up , down , left , right };
985
996
const diag_move = init : {
@@ -1296,9 +1307,8 @@ pub fn EnumIndexer(comptime E: type) type {
1296
1307
1297
1308
const const_fields = std .meta .fields (E );
1298
1309
var fields = const_fields [0.. const_fields .len ].* ;
1299
- const min = fields [0 ].value ;
1300
- const max = fields [fields .len - 1 ].value ;
1301
1310
const fields_len = fields .len ;
1311
+
1302
1312
if (fields_len == 0 ) {
1303
1313
return struct {
1304
1314
pub const Key = E ;
@@ -1314,6 +1324,9 @@ pub fn EnumIndexer(comptime E: type) type {
1314
1324
};
1315
1325
}
1316
1326
1327
+ const min = fields [0 ].value ;
1328
+ const max = fields [fields .len - 1 ].value ;
1329
+
1317
1330
const SortContext = struct {
1318
1331
fields : []EnumField ,
1319
1332
@@ -1424,3 +1437,11 @@ test "std.enums.EnumIndexer sparse" {
1424
1437
try testing .expectEqual (E .b , Indexer .keyForIndex (1 ));
1425
1438
try testing .expectEqual (E .c , Indexer .keyForIndex (2 ));
1426
1439
}
1440
+
1441
+ test "std.enums.EnumIndexer empty" {
1442
+ const E = enum {};
1443
+ const Indexer = EnumIndexer (E );
1444
+ ensureIndexer (Indexer );
1445
+ try testing .expectEqual (E , Indexer .Key );
1446
+ try testing .expectEqual (@as (usize , 0 ), Indexer .count );
1447
+ }
0 commit comments