From 6d29253e8c3fdea828df86215fe5ea9e69870b94 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Wed, 3 Aug 2022 12:58:15 -0600 Subject: [PATCH] Add more to the test --- src/LDtk.zig | 4 ++-- src/main.zig | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/LDtk.zig b/src/LDtk.zig index 61c8938..ee2deec 100644 --- a/src/LDtk.zig +++ b/src/LDtk.zig @@ -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 diff --git a/src/main.zig b/src/main.zig index cb729d9..5532ae8 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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.?); +}