@@ -176,8 +176,8 @@ const TestContext = struct {
176176
177177 pub fn processMessage (self : * TestContext , msg : anytype ) ! void {
178178 var json_message : []const u8 = undefined ;
179- if (@typeInfo (@TypeOf (msg )) != .Pointer ) {
180- json_message = try json .stringifyAlloc (self .arena .allocator (), msg , .{});
179+ if (@typeInfo (@TypeOf (msg )) != .pointer ) {
180+ json_message = try std . json .stringifyAlloc (self .arena .allocator (), msg , .{});
181181 } else {
182182 // assume this is a string we want to send as-is, if it isn't, we'll
183183 // get a compile error, so no big deal.
@@ -198,7 +198,7 @@ const TestContext = struct {
198198 pub fn expectSentResult (self : * TestContext , expected : anytype , opts : ExpectResultOpts ) ! void {
199199 const expected_result = .{
200200 .id = opts .id ,
201- .result = if (comptime @typeInfo (@TypeOf (expected )) == .Null ) struct {}{} else expected ,
201+ .result = if (comptime @typeInfo (@TypeOf (expected )) == .null ) struct {}{} else expected ,
202202 .sessionId = opts .session_id ,
203203 };
204204
@@ -212,7 +212,7 @@ const TestContext = struct {
212212 pub fn expectSentEvent (self : * TestContext , method : []const u8 , params : anytype , opts : ExpectEventOpts ) ! void {
213213 const expected_event = .{
214214 .method = method ,
215- .params = if (comptime @typeInfo (@TypeOf (params )) == .Null ) struct {}{} else params ,
215+ .params = if (comptime @typeInfo (@TypeOf (params )) == .null ) struct {}{} else params ,
216216 .sessionId = opts .session_id ,
217217 };
218218
@@ -324,96 +324,3 @@ fn compareJsonValues(a: std.json.Value, b: std.json.Value) bool {
324324 },
325325 }
326326}
327-
328- // fn compareAnyToJsonValue(expected: anytype, actual: json.Value) bool {
329- // switch (@typeInfo(@TypeOf(expected))) {
330- // .Optional => {
331- // if (expected) |e| {
332- // return compareAnyToJsonValue(e, actual);
333- // }
334- // return actual == .null;
335- // },
336- // .Int, .ComptimeInt => {
337- // if (actual != .integer) {
338- // return false;
339- // }
340- // return expected == actual.integer;
341- // },
342- // .Float, .ComptimeFloat => {
343- // if (actual != .float) {
344- // return false;
345- // }
346- // return expected == actual.float;
347- // },
348- // .Bool => {
349- // if (actual != .bool) {
350- // return false;
351- // }
352- // return expected == actual.bool;
353- // },
354- // .Pointer => |ptr| switch (ptr.size) {
355- // .One => switch (@typeInfo(ptr.child)) {
356- // .Struct => return compareAnyToJsonValue(expected.*, actual),
357- // .Array => |arr| if (arr.child == u8) {
358- // if (actual != .string) {
359- // return false;
360- // }
361- // return std.mem.eql(u8, expected, actual.string);
362- // },
363- // else => {},
364- // },
365- // .Slice => switch (ptr.child) {
366- // u8 => {
367- // if (actual != .string) {
368- // return false;
369- // }
370- // return std.mem.eql(u8, expected, actual.string);
371- // },
372- // else => {},
373- // },
374- // else => {},
375- // },
376- // .Struct => |s| {
377- // if (s.is_tuple) {
378- // // how an array might look in an anytype
379- // if (actual != .array) {
380- // return false;
381- // }
382- // if (s.fields.len != actual.array.items.len) {
383- // return false;
384- // }
385-
386- // inline for (s.fields, 0..) |f, i| {
387- // const e = @field(expected, f.name);
388- // if (compareAnyToJsonValue(e, actual.array.items[i]) == false) {
389- // return false;
390- // }
391- // }
392- // return true;
393- // }
394-
395- // if (s.fields.len == 0) {
396- // return (actual == .array and actual.array.items.len == 0);
397- // }
398-
399- // if (actual != .object) {
400- // return false;
401- // }
402- // inline for (s.fields) |f| {
403- // const e = @field(expected, f.name);
404- // if (actual.object.get(f.name)) |a| {
405- // if (compareAnyToJsonValue(e, a) == false) {
406- // return false;
407- // }
408- // } else if (@typeInfo(f.type) != .Optional or e != null) {
409- // // We don't JSON serialize nulls. So if we're expecting
410- // // a null, that should show up as a missing field.
411- // return false;
412- // }
413- // }
414- // return true;
415- // },
416- // else => {},
417- // }
418- // @compileError("Can't compare " ++ @typeName(@TypeOf(expected)));
419- // }
0 commit comments