Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Private Function

expectEqualEnum

Private Function
std.meta.expectEqualEnum
fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void

Params

  • expected
  • actual: @TypeOf(expected)

File

meta.zig:426
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
fn expectEqualEnum(expected: anytype, actual: @TypeOf(expected)) !void {
    try testing.expectEqual(@typeInfo(expected).@"enum", @typeInfo(actual).@"enum");
    try testing.expectEqual(
        @typeInfo(expected).@"enum".tag_type,
        @typeInfo(actual).@"enum".tag_type,
    );
    // For comparing decls and fields, we cannot use the meta eql function here
    // because the language does not guarantee that the slice pointers for field names
    // and decl names will be the same.
    comptime {
        const expected_field_names = @typeInfo(expected).@"enum".field_names;
        const expected_field_values = @typeInfo(expected).@"enum".field_values;
        const actual_field_names = @typeInfo(actual).@"enum".field_names;
        const actual_field_values = @typeInfo(actual).@"enum".field_values;
        if (expected_field_names.len != actual_field_names.len) return error.FailedTest;
        for (expected_field_names, expected_field_values, 0..) |expected_field_name, expected_field_value, i| {
            const actual_field_name = actual_field_names[i];
            const actual_field_value = actual_field_values[i];
            try testing.expectEqual(expected_field_value, actual_field_value);
            try testing.expectEqualStrings(expected_field_name, actual_field_name);
        }
    }
    comptime {
        const expected_decl_names = @typeInfo(expected).@"enum".decl_names;
        const actual_decl_names = @typeInfo(actual).@"enum".decl_names;
        if (expected_decl_names.len != actual_decl_names.len) return error.FailedTest;
        for (expected_decl_names, 0..) |expected_decl_name, i| {
            const actual_decl_name = actual_decl_names[i];
            try testing.expectEqualStrings(expected_decl_name, actual_decl_name);
        }
    }
    try testing.expectEqual(
        @typeInfo(expected).@"enum".mode,
        @typeInfo(actual).@"enum".mode,
    );
}