Skip to content

Commit

Permalink
Add unit test for default program init (#461)
Browse files Browse the repository at this point in the history
Co-authored-by: lanaivina <[email protected]>
  • Loading branch information
tcoratger and lana-shanghai authored Mar 13, 2024
1 parent b235b2e commit 295b93b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/vm/types/program.zig
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub const SharedProgramData = struct {
/// List of error message attributes.
error_message_attributes: std.ArrayList(Attribute),
/// Map of `usize` to `InstructionLocation`.
instruction_locations: ?std.StringHashMap(InstructionLocation),
instruction_locations: ?std.StringHashMap(InstructionLocation) = null,
/// Map of `[]u8` to `Identifier`.
identifiers: std.StringHashMap(Identifier),
/// List of `HintReference` items.
Expand All @@ -244,7 +244,6 @@ pub const SharedProgramData = struct {
.data = std.ArrayList(MaybeRelocatable).init(allocator),
.hints_collection = try HintsCollection.initDefault(allocator, extensive_hints),
.error_message_attributes = std.ArrayList(Attribute).init(allocator),
.instruction_locations = std.StringHashMap(InstructionLocation).init(allocator),
.identifiers = std.StringHashMap(Identifier).init(allocator),
.reference_manager = std.ArrayList(HintReference).init(allocator),
};
Expand Down Expand Up @@ -1224,3 +1223,19 @@ test "Program: new program with non-extensive hints" {
try expect(hints.get(4).?.len == 1);
try expectEqualDeep(hints.get(4).?[0], program_hints.get(4).?[0]);
}

test "Program: new default program" {
var program = try Program.initDefault(std.testing.allocator, false);
defer program.deinit(std.testing.allocator);

try expect(program.shared_program_data.data.items.len == 0);
try expect(program.shared_program_data.hints_collection.hints.items.len == 0);
try expect(program.shared_program_data.hints_collection.hints_ranges == .NonExtensive);
try expect(program.shared_program_data.main == null);
try expect(program.shared_program_data.start == null);
try expect(program.shared_program_data.end == null);
try expect(program.shared_program_data.error_message_attributes.items.len == 0);
try expect(program.shared_program_data.instruction_locations == null);
try expectEqual(@as(usize, 0), program.shared_program_data.identifiers.count());
try expect(program.shared_program_data.reference_manager.items.len == 0);
}

0 comments on commit 295b93b

Please sign in to comment.