Skip to content

Commit

Permalink
Remove unused variables and unused tests
Browse files Browse the repository at this point in the history
Makes the code compatible with zig version 0.9.0-dev.339

I removed a test that included only local string constants and did not
call any code from the library.
  • Loading branch information
leroycep committed Jul 2, 2021
1 parent 2562569 commit 3f01eb5
Showing 1 changed file with 26 additions and 51 deletions.
77 changes: 26 additions & 51 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,6 @@ pub const ZValue = union(enum) {
const chars_count = @sizeOf(@TypeOf(chars));
var need_escape = false;
var found = [_]bool{false} ** chars_count;
var level: usize = 0;
for ("\"\n\t\r,:;") |ch, i| {
const f = find(u8, self.String, ch);
if (f != null) {
Expand Down Expand Up @@ -620,6 +619,8 @@ pub const ZValue = union(enum) {

///
pub fn format(self: Self, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
_ = fmt;
_ = options;
switch (self) {
.Null => try std.fmt.format(writer, ".Null", .{}),
.String => try std.fmt.format(writer, ".String({s})", .{self.String}),
Expand Down Expand Up @@ -836,7 +837,7 @@ pub const ZNode = struct {
}

/// Traverses descendants until a node with the tag is found.
pub fn findNthAnyDescendant(self: *const Self, nth: usize, value: std.meta.Tag(ZValue)) ?*ZNode {
pub fn findNthAnyDescendant(self: *const Self, nth: usize, tag: std.meta.Tag(ZValue)) ?*ZNode {
var depth: isize = 0;
var count: usize = 0;
var iter: *const ZNode = self;
Expand Down Expand Up @@ -878,8 +879,8 @@ pub const ZNode = struct {
}
// Try to cast to numbers, then true/false checks, then string.
const slice = c.value.String;
const integer = std.fmt.parseInt(i32, slice, 10) catch |_| {
const float = std.fmt.parseFloat(f32, slice) catch |_| {
const integer = std.fmt.parseInt(i32, slice, 10) catch {
const float = std.fmt.parseFloat(f32, slice) catch {
if (std.mem.eql(u8, "true", slice)) {
c.value = ZValue{ .Bool = true };
} else if (std.mem.eql(u8, "false", slice)) {
Expand Down Expand Up @@ -933,7 +934,7 @@ pub const ZNode = struct {
.Enum => {
switch (self.value) {
.Int => |int| {
return std.meta.intToEnum(T, int) catch |_| {
return std.meta.intToEnum(T, int) catch {
return ImprintError.FailedToConvertIntToEnum;
};
},
Expand All @@ -960,7 +961,7 @@ pub const ZNode = struct {
var iter: ?*const ZNode = null;
var result: T = .{};

inline for (struct_info.fields) |field, i| {
inline for (struct_info.fields) |field| {
// Skip underscores.
if (field.name[0] == '_') {
continue;
Expand Down Expand Up @@ -1327,7 +1328,7 @@ pub fn ZTree(comptime R: usize, comptime S: usize) type {

/// Debug print the tree and all of its roots.
pub fn show(self: *const Self) void {
for (self.rootSlice()) |rt, i| {
for (self.rootSlice()) |rt| {
rt.show();
}
}
Expand Down Expand Up @@ -1359,15 +1360,13 @@ pub fn ZTree(comptime R: usize, comptime S: usize) type {
.Enum => {
_ = try self.addNode(root, .{ .String = std.meta.tagName(from_ptr.*) });
},
.Optional => |opt_info| {
.Optional => {
if (from_ptr.* != null) {
return self.extract(root, &from_ptr.*.?);
}
},
.Struct => |struct_info| {
var iter: ?*const ZNode = null;

inline for (struct_info.fields) |field, i| {
inline for (struct_info.fields) |field| {
if (field.name[field.name.len - 1] == '_') {
continue;
}
Expand Down Expand Up @@ -1466,12 +1465,12 @@ test "node appending and searching" {
var tree = ZTree(1, 100){};
var root = try tree.addNode(null, .Null);

var nullChild = try tree.addNode(root, .Null);
var stringChild = try tree.addNode(root, .{ .String = "Hello" });
var fooChild = try tree.addNode(root, .{ .String = "foo" });
var integerChild = try tree.addNode(root, .{ .Int = 42 });
var floatChild = try tree.addNode(root, .{ .Float = 3.14 });
var boolChild = try tree.addNode(root, .{ .Bool = true });
_ = try tree.addNode(root, .Null);
_ = try tree.addNode(root, .{ .String = "Hello" });
_ = try tree.addNode(root, .{ .String = "foo" });
_ = try tree.addNode(root, .{ .Int = 42 });
_ = try tree.addNode(root, .{ .Float = 3.14 });
_ = try tree.addNode(root, .{ .Bool = true });

try testing.expectEqual(@as(usize, 6), root.getChildCount());
try testing.expect(root.findNth(0, .Null) != null);
Expand Down Expand Up @@ -1502,35 +1501,12 @@ test "node appending and searching" {
try testing.expect(root.findNth(1, .{ .Bool = true }) == null);
}

test "parsing into nodes" {
const testing = std.testing;
const text1 =
\\elements: fire,water,air,earth
\\subelements:
\\ fire: lightning
\\ water: blood; ice
\\ air: spirit
\\ earth: [[metal]]
;
const text2 =
\\elements:fire,water,air,earth;
\\subelements:fire:lightning;water:blood;ice,air:spirit,;earth:metal;;
;
const text =
\\name:wizard;
\\stats
\\ : health:10
\\ mana:30
;
}

test "node conforming imprint" {
const testing = std.testing;

const ConformingEnum = enum {
Foo,
};
comptime var x: i32 = 0;

const ConformingSubStruct = struct {
name: []const u8 = "default",
Expand Down Expand Up @@ -1561,14 +1537,14 @@ test "node conforming imprint" {
var node = try tree.appendText(text);
node.convertStrings();

//const example = try node.imprint(ConformingStruct);
//try testing.expectEqual(@as(i32, 100), example.max_particles.?);
//try testing.expectEqualSlices(u8, "circle", example.texture);
//try testing.expect(null != example.systems[0]);
//try testing.expect(null != example.systems[1]);
//try testing.expectEqual(@as(?ConformingSubStruct, null), example.systems[2]);
//try testing.expectEqual(ConformingEnum.Foo, example.en.?);
//try testing.expectEqualSlices(u8, "params", example.systems[0].?.params.?.value.String);
const example = try node.imprint(ConformingStruct);
try testing.expectEqual(@as(i32, 100), example.max_particles.?);
try testing.expectEqualSlices(u8, "circle", example.texture);
try testing.expect(null != example.systems[0]);
try testing.expect(null != example.systems[1]);
try testing.expectEqual(@as(?ConformingSubStruct, null), example.systems[2]);
try testing.expectEqual(ConformingEnum.Foo, example.en.?);
try testing.expectEqualSlices(u8, "params", example.systems[0].?.params.?.value.String);
}

test "node nonconforming imprint" {
Expand Down Expand Up @@ -1639,7 +1615,6 @@ test "imprint allocations" {
}

test "extract" {
const testing = std.testing;
var text_tree = ZTree(1, 100){};
var text_root = try text_tree.appendText("foo:bar:baz;;42");

Expand Down Expand Up @@ -1749,7 +1724,7 @@ const FooBar = struct {
interface: FooInterface = .{},
bar: i32 = 0,

pub fn zinit(allocator: *std.mem.Allocator, argz: *const ZNode) !*FooInterface {
pub fn zinit(allocator: *std.mem.Allocator, _: *const ZNode) !*FooInterface {
var self = try allocator.create(Self);
self.* = .{
.interface = .{
Expand All @@ -1769,7 +1744,7 @@ const FooBar = struct {
}

pub fn foo(interface: *FooInterface) void {
var self = @fieldParentPtr(FooBar, "interface", interface);
_ = @fieldParentPtr(FooBar, "interface", interface);
}
};

Expand Down

0 comments on commit 3f01eb5

Please sign in to comment.