Skip to content

Commit 4240458

Browse files
authored
wiptest -> test (#2131)
* +/- for object diff, quote more strings * wiptest -> test * quote strings fix
1 parent e8c9c64 commit 4240458

File tree

5 files changed

+97
-33
lines changed

5 files changed

+97
-33
lines changed

src/bun.js/api/bun.zig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ pub fn inspect(
247247
false,
248248
false,
249249
false,
250-
false,
251250
);
252251
buffered_writer.flush() catch {
253252
return JSC.C.JSValueMakeUndefined(ctx);

src/bun.js/bindings/exports.zig

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,6 @@ pub const ZigConsoleClient = struct {
968968
true,
969969
true,
970970
false,
971-
false,
972971
)
973972
else if (message_type == .Log) {
974973
_ = console.writer.write("\n") catch 0;
@@ -1018,7 +1017,6 @@ pub const ZigConsoleClient = struct {
10181017
add_newline: bool,
10191018
flush: bool,
10201019
order_properties: bool,
1021-
quote_strings: bool,
10221020
) void {
10231021
var fmt: ZigConsoleClient.Formatter = undefined;
10241022
defer {
@@ -1034,7 +1032,6 @@ pub const ZigConsoleClient = struct {
10341032
.remaining_values = &[_]JSValue{},
10351033
.globalThis = global,
10361034
.ordered_properties = order_properties,
1037-
.quote_strings = quote_strings,
10381035
};
10391036
const tag = ZigConsoleClient.Formatter.Tag.get(vals[0], global);
10401037

@@ -1112,7 +1109,6 @@ pub const ZigConsoleClient = struct {
11121109
.remaining_values = vals[0..len][1..],
11131110
.globalThis = global,
11141111
.ordered_properties = order_properties,
1115-
.quote_strings = quote_strings,
11161112
};
11171113
var tag: ZigConsoleClient.Formatter.Tag.Result = undefined;
11181114

@@ -1893,6 +1889,7 @@ pub const ZigConsoleClient = struct {
18931889
writer.print(comptime Output.prettyFmt("<r><red>", enable_ansi_colors), .{});
18941890
}
18951891

1892+
if (jsType != .RegExpObject) writer.writeAll("\"");
18961893
if (str.is16Bit()) {
18971894
// streaming print
18981895
writer.print("{s}", .{str});
@@ -1907,6 +1904,7 @@ pub const ZigConsoleClient = struct {
19071904
writer.writeAll(buf);
19081905
}
19091906
}
1907+
if (jsType != .RegExpObject) writer.writeAll("\"");
19101908

19111909
if (jsType == .RegExpObject and enable_ansi_colors) {
19121910
writer.print(comptime Output.prettyFmt("<r>", enable_ansi_colors), .{});

src/bun.js/test/jest.zig

Lines changed: 87 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ pub const DiffFormatter = struct {
9696
false,
9797
false,
9898
true,
99-
true,
10099
);
101100
buffered_writer.flush() catch unreachable;
102101

@@ -114,7 +113,6 @@ pub const DiffFormatter = struct {
114113
false,
115114
false,
116115
true,
117-
true,
118116
);
119117
buffered_writer.flush() catch unreachable;
120118
}
@@ -132,14 +130,10 @@ pub const DiffFormatter = struct {
132130
return;
133131
}
134132

135-
const equal_fmt = "<d>{s}<r>";
136-
const delete_fmt = "<red>{s}<r>";
137-
const insert_fmt = "<green>{s}<r>";
138-
139133
switch (this.received.determineDiffMethod(this.expected, this.globalObject)) {
140134
.none => {
141135
const fmt = "Expected: <green>{any}<r>\nReceived: <red>{any}<r>";
142-
var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = this.globalObject, .quote_strings = true };
136+
var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = this.globalObject };
143137
if (Output.enable_ansi_colors) {
144138
try writer.print(Output.prettyFmt(fmt, true), .{
145139
this.expected.toFmt(this.globalObject, &formatter),
@@ -160,21 +154,49 @@ pub const DiffFormatter = struct {
160154
var diffs = try dmp.diff(default_allocator, received_slice, expected_slice, false);
161155
defer diffs.deinit(default_allocator);
162156

163-
try writer.writeAll(Output.prettyFmt("Expected: ", true));
157+
const equal_fmt = "<d>{s}<r>";
158+
const delete_fmt = "<red>{s}<r>";
159+
const insert_fmt = "<green>{s}<r>";
160+
161+
try writer.writeAll("Expected: ");
164162
for (diffs.items) |df| {
165163
switch (df.operation) {
166164
.delete => continue,
167-
.insert => try writer.print(Output.prettyFmt(insert_fmt, true), .{df.text}),
168-
.equal => try writer.print(Output.prettyFmt(equal_fmt, true), .{df.text}),
165+
.insert => {
166+
if (Output.enable_ansi_colors) {
167+
try writer.print(Output.prettyFmt(insert_fmt, true), .{df.text});
168+
} else {
169+
try writer.print(Output.prettyFmt(insert_fmt, false), .{df.text});
170+
}
171+
},
172+
.equal => {
173+
if (Output.enable_ansi_colors) {
174+
try writer.print(Output.prettyFmt(equal_fmt, true), .{df.text});
175+
} else {
176+
try writer.print(Output.prettyFmt(equal_fmt, false), .{df.text});
177+
}
178+
},
169179
}
170180
}
171181

172-
try writer.writeAll(Output.prettyFmt("\nReceived: ", true));
182+
try writer.writeAll("\nReceived: ");
173183
for (diffs.items) |df| {
174184
switch (df.operation) {
175185
.insert => continue,
176-
.delete => try writer.print(Output.prettyFmt(delete_fmt, true), .{df.text}),
177-
.equal => try writer.print(Output.prettyFmt(equal_fmt, true), .{df.text}),
186+
.delete => {
187+
if (Output.enable_ansi_colors) {
188+
try writer.print(Output.prettyFmt(delete_fmt, true), .{df.text});
189+
} else {
190+
try writer.print(Output.prettyFmt(delete_fmt, false), .{df.text});
191+
}
192+
},
193+
.equal => {
194+
if (Output.enable_ansi_colors) {
195+
try writer.print(Output.prettyFmt(equal_fmt, true), .{df.text});
196+
} else {
197+
try writer.print(Output.prettyFmt(equal_fmt, false), .{df.text});
198+
}
199+
},
178200
}
179201
}
180202
return;
@@ -185,34 +207,74 @@ pub const DiffFormatter = struct {
185207
var diffs = try dmp.diffLines(default_allocator, received_slice, expected_slice);
186208
defer diffs.deinit(default_allocator);
187209

210+
const equal_fmt = "<d> {s}<r>";
211+
const delete_fmt = "<red>+ {s}<r>";
212+
const insert_fmt = "<green>- {s}<r>";
213+
188214
var insert_count: usize = 0;
189215
var delete_count: usize = 0;
190216

191217
for (diffs.items) |df| {
218+
var prev: usize = 0;
219+
var curr: usize = 0;
192220
switch (df.operation) {
193221
.equal => {
194-
try writer.print(Output.prettyFmt(equal_fmt, true), .{df.text});
222+
while (curr < df.text.len) {
223+
if (curr == df.text.len - 1 or df.text[curr] == '\n' and curr != 0) {
224+
if (Output.enable_ansi_colors) {
225+
try writer.print(Output.prettyFmt(equal_fmt, true), .{df.text[prev .. curr + 1]});
226+
} else {
227+
try writer.print(Output.prettyFmt(equal_fmt, false), .{df.text[prev .. curr + 1]});
228+
}
229+
prev = curr + 1;
230+
}
231+
curr += 1;
232+
}
195233
},
196234
.insert => {
197-
for (df.text) |c| {
198-
if (c == '\n') insert_count += 1;
235+
while (curr < df.text.len) {
236+
if (curr == df.text.len - 1 or df.text[curr] == '\n' and curr != 0) {
237+
insert_count += 1;
238+
if (Output.enable_ansi_colors) {
239+
try writer.print(Output.prettyFmt(insert_fmt, true), .{df.text[prev .. curr + 1]});
240+
} else {
241+
try writer.print(Output.prettyFmt(insert_fmt, false), .{df.text[prev .. curr + 1]});
242+
}
243+
prev = curr + 1;
244+
}
245+
curr += 1;
199246
}
200-
try writer.print(Output.prettyFmt(insert_fmt, true), .{df.text});
201247
},
202248
.delete => {
203-
for (df.text) |c| {
204-
if (c == '\n') delete_count += 1;
249+
while (curr < df.text.len) {
250+
if (curr == df.text.len - 1 or df.text[curr] == '\n' and curr != 0) {
251+
delete_count += 1;
252+
if (Output.enable_ansi_colors) {
253+
try writer.print(Output.prettyFmt(delete_fmt, true), .{df.text[prev .. curr + 1]});
254+
} else {
255+
try writer.print(Output.prettyFmt(delete_fmt, false), .{df.text[prev .. curr + 1]});
256+
}
257+
prev = curr + 1;
258+
}
259+
curr += 1;
205260
}
206-
try writer.print(Output.prettyFmt(delete_fmt, true), .{df.text});
207261
},
208262
}
209263
}
210264

211-
try writer.print(Output.prettyFmt("\n\n<green>- Expected - {d}<r>\n", true), .{insert_count});
212-
try writer.print(Output.prettyFmt("<red>+ Received + {d}<r>", true), .{delete_count});
265+
if (Output.enable_ansi_colors) {
266+
try writer.print(Output.prettyFmt("\n\n<green>- Expected - {d}<r>\n", true), .{insert_count});
267+
try writer.print(Output.prettyFmt("<red>+ Received + {d}<r>", true), .{delete_count});
268+
return;
269+
}
270+
try writer.print("\n\n- Expected - {d}\n", .{insert_count});
271+
try writer.print("+ Received + {d}", .{delete_count});
213272
return;
214273
},
215-
.word => {},
274+
.word => {
275+
// not implemented
276+
// https://github.com/google/diff-match-patch/wiki/Line-or-Word-Diffs#word-mode
277+
},
216278
}
217279
return;
218280
}
@@ -502,7 +564,7 @@ pub const Expect = struct {
502564
if (pass) return thisValue;
503565

504566
// handle failure
505-
var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = globalObject, .quote_strings = true };
567+
var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = globalObject };
506568
if (not) {
507569
const signature = comptime getSignature("toBe", "<green>expected<r>", true);
508570
const fmt = signature ++ "\n\nExpected: not <green>{any}<r>\n";
@@ -1191,7 +1253,7 @@ pub const Expect = struct {
11911253
if (pass) return thisValue;
11921254

11931255
// handle failure
1194-
var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = globalObject, .quote_strings = true };
1256+
var formatter = JSC.ZigConsoleClient.Formatter{ .globalThis = globalObject };
11951257
if (not) {
11961258
if (expected_property != null) {
11971259
const signature = comptime getSignature("toHaveProperty", "<green>path<r><d>, <r><green>value<r>", true);

src/cli.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ pub const Command = struct {
938938
},
939939
RootCommandMatcher.case("c"), RootCommandMatcher.case("create") => .CreateCommand,
940940

941-
RootCommandMatcher.case(TestCommand.name) => .TestCommand,
941+
RootCommandMatcher.case(TestCommand.name), RootCommandMatcher.case(TestCommand.old_name) => .TestCommand,
942942

943943
RootCommandMatcher.case("pm") => .PackageManagerCommand,
944944

src/cli/test_command.zig

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,16 @@ const Scanner = struct {
342342
};
343343

344344
pub const TestCommand = struct {
345-
pub const name = "wiptest";
345+
pub const name = "test";
346+
pub const old_name = "wiptest";
346347
pub fn exec(ctx: Command.Context) !void {
347348
if (comptime is_bindgen) unreachable;
348349
// print the version so you know its doing stuff if it takes a sec
349-
Output.prettyErrorln("<r><b>bun wiptest <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{});
350+
if (strings.eqlComptime(ctx.positionals[0], old_name)) {
351+
Output.prettyErrorln("<r><b>bun wiptest <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{});
352+
} else {
353+
Output.prettyErrorln("<r><b>bun test <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>", .{});
354+
}
350355
Output.flush();
351356

352357
var env_loader = brk: {

0 commit comments

Comments
 (0)