Add more to the test

dev
Louis Pearson 2022-08-03 12:58:15 -06:00
parent f2d59bbcd7
commit 6d29253e8c
2 changed files with 20 additions and 3 deletions

View File

@ -98,7 +98,7 @@ pub const WorldLayout = enum {
/// 2. Level
pub const Level = struct {
__bgColor: ?[]const u8,
__bgColor: []const u8,
__bgPos: ?struct {
cropRect: [4]f64,
scale: [2]f64,
@ -122,7 +122,7 @@ pub const Level = struct {
const level_obj = object(level_opt) orelse return error.InvalidLevel;
const layer_instances = if (level_obj.get("layerInstances")) |layerInstances| try LayerInstance.fromJSONMany(alloc, layerInstances) else null;
return Level{
.__bgColor = string(level_obj.get("__bgColor")),
.__bgColor = string(level_obj.get("__bgColor")) orelse return error.Invalid__bgColor,
// TODO
.__bgPos = null,
// TODO

View File

@ -14,5 +14,22 @@ test "load default/empty ldtk file" {
try testing.expectEqual(@as(?i64, 256), ldtk_root.worldGridWidth);
try testing.expectEqual(@as(?LDtk.WorldLayout, LDtk.WorldLayout.Free), ldtk_root.worldLayout);
try testing.expect(!ldtk_root.externalLevels);
}
try testing.expectEqual(@as(usize, 1), ldtk_root.levels.len);
const level_0 = ldtk_root.levels[0];
try testing.expectEqualStrings("Level_0", level_0.identifier);
try testing.expectEqualStrings("c0773b00-02f0-11ed-bf2c-25905856c5d2", level_0.iid);
try testing.expectEqualStrings("#696A79", level_0.__bgColor);
try testing.expectEqual(@as(i64, 0), level_0.uid);
try testing.expectEqual(@as(i64, 0), level_0.worldX);
try testing.expectEqual(@as(i64, 0), level_0.worldY);
try testing.expectEqual(@as(i64, 0), level_0.worldDepth);
try testing.expectEqual(@as(i64, 256), level_0.pxWid);
try testing.expectEqual(@as(i64, 256), level_0.pxHei);
try testing.expectEqual(@as(?[]const u8, null), level_0.externalRelPath);
try testing.expectEqual(@as(?[]const u8, null), level_0.bgRelPath);
try testing.expectEqualSlices(LDtk.Neighbour, &[_]LDtk.Neighbour{}, level_0.__neighbours);
try testing.expectEqualSlices(LDtk.FieldInstance, &[_]LDtk.FieldInstance{}, level_0.fieldInstances);
try testing.expectEqualSlices(LDtk.LayerInstance, &[_]LDtk.LayerInstance{}, level_0.layerInstances.?);
}